How to Connect Visual Basic 6 to MSAccess?
I have created two types of connections string, first is the database file is targeted via patch provided.
Sub OpenDataFiles(ByRef adConnData As ADODB.Connection, ByRef adrsdata As ADODB.Recordset, ByVal adfile As String, ByVal squery As String)
Dim connstring As String
Set adConnData = New ADODB.Connection
If adfile = "" Then adfile = "c:\mydatabase\data.mdb"
connstring = "provider=microsoft.jet.oledb.4.0;data source=" & App.Path & "\" & adfile
adConnData.ConnectionString = connstring
adConnData.Open
adConnData.CursorLocation = adUseClient
Set adrsdata = New ADODB.Recordset
adrsdata.Open squery, adConnData, adOpenKeyset, adLockOptimistic
End Sub
Two, the Access database file is placed along the program folder.
Sub OpenDataFiles(ByRef adConnData As ADODB.Connection, ByRef adrsdata As ADODB.Recordset, ByVal adfile As String, ByVal squery As String)
Dim connstring As String
Set adConnData = New ADODB.Connection
connstring = "provider=microsoft.jet.oledb.4.0;data source=" & App.Path & "database.mdb" adConnData.ConnectionString = connstring
adConnData.Open
adConnData.CursorLocation = adUseClient
Set adrsdata = New ADODB.Recordset
adrsdata.Open squery, adConnData, adOpenKeyset, adLockOptimistic
End Sub
Regardless of the path, you can specify it on the Visual Basic 6.0 Data Environment.