Declarations
'Class Module MyDataClass.cls
'General Declarations for class module
Private m_PVD As ADODB.Connection
'General Declarations of a form or Class Module
Private rsData As ADODB.Recordset
'Reference to the DSN-Less Connection Class
Private oData As MyDataClass
Code
'Class Code
Public Function MainDataConnection() As ADODB.Connection
Set MainDataConnection = m_PVD
End Function
Private Sub Class_Initialize()
'Create a DSN-Less connection, this one uses Pervasive WGE 8.10
' however it should work with others
Set m_PVD = New ADODB.Connection
m_PVD.Open "Provider=PervasiveOLEDB.8.10;Data Source=MyData"
'Set the connection's CursorLocation property to adUseClient
'Don't use adUseServer else it won't work!
m_PVD.CursorLocation = adUseClient
End Sub
Private Sub Class_Terminate()
'Kill the connection
m_PVD.Close
Set m_PVD = Nothing
End Sub
'END CLASS CODE
Sub GetRecCount()
'The rest is fairly simple.
Dim strSQL As String
Dim dConn As ADODB.Connection
Set rsData = New ADODB.Recordset
Set oData = New MyDataClass
Set dConn = oData.MainDataConnection
strSQL = "SELECT * FROM FCDSTATSIX, FCDUISTAT WHERE FCTSIXDEX = IDX_COUNT ORDER BY IDX_COUNT"
'Get the records and the record count.
rsData.Open strSQL, dConn,,, adCmdText
For i = 0 To rsData.RecordCount
'Do something useful with records and recordcount
rsData.MoveNext
Next
End Sub