Private Sub Command1_Click()
Dim connection1 As New ADODB.Connection
Dim recset1 As New ADODB.Recordset
Dim iCount&
Dim strConnectionString$
On Error GoTo Er
rorHandler
' connect to default iHistorian server with default credentials
strConnectionString$ = "Provider=ihOLEDB.iHistorian.1;User Id=;Password="
' uncomment this if you want to connect to specific iHistorian server with a username and password
'strConnectionString$ = "Provider=ihOLEDB.iHistorian.1;Data Source=MYSERVER;User Id=user1;Password=password1"
' open connection
connection1.ConnectionString = strConnectionString$
connection1.Open
' do the select. There are multiple ways to execute a command in ADO, this is just one
recset1.Open "SELECT * FROM ihTags", connection1
' print the output
iCount = 0
Do While Not recset1.EOF
Debug.Print recset1.Fields(0)
recset1.MoveNext
iCount = iCount + 1
Loop
' print a count of rows
If iCount = 0 Then
MsgBox "No rows were returned in the query"
Else
MsgBox iCount & " rows returned."
End If
' close the recordset
recset1.Close
Set recset1 = Nothing
' close the connection
connection1.Close
Exit Sub
ErrorHandler:
MsgBox Err.Description
End Sub