Client Interfaces Guide > Connecting to TDV Server through ODBC > Examples Using ODBC to Connect to TDV Server > VBA Code Sample for Connecting to TDV Server
 
VBA Code Sample for Connecting to TDV Server
The following is a sample Visual Basic for Applications (VBA) Script for connecting to TDV Server from a Microsoft client (such as Excel) through ADO.
Sub demo()
On Error Resume Next
Err.Clear
dsn = "DS-Composite"
Set conn = CreateObject("ADODB.Connection")
conn.Open
Driver={TDV <ver>};host=localhost;port=9451;sso=(Disabled);uid=admin;pwd=admin;datasource=examples;domain=composite;
If Err.Number <> 0 Then
‘process error
Exit Sub
End If
Err.Clear
Set rs = CreateObject("ADODB.Recordset")
rs.Open "SELECT * FROM CUSTOMER", conn
If Err.Number <> 0 Then
' process error
Exit Sub
End If
' get column names
For Each Column In rs.fields
colname = Column.Name
Next
' get first 100 rows
Count = 0
maxcount = 100
Err.Clear
Do While Not rs.EOF And Err.Number = 0 And Count < maxcount
Count = Count + 1
For Each Record In rs.fields
colvalue = Record.Value
Next
rs.movenext
Loop
End Sub