TC -
I use the following code snippets to connect
VB to MSAccess tables locally and in networks. It uses ADO and the MSJet driver. I put it in the globals.bas file. You must add the ADO data objects reference to your project.
Public m_JETDir As String 'drive and directory of mdb file
Public m_JETmdb As String 'name and extension of mdb file
Public Xconx As ADODB.Connection
Public Xcmd As ADODB.Command
Public Xrs As ADODB.Recordset
-------------------------------------------------------
Sub JETCONX() 'make connection to MSAccess Database
Set Xconx = New ADODB.Connection
Set Xcmd = New ADODB.Command
Set Xrs = New ADODB.Recordset
Set Xconx = CreateObject("ADODB.Connection")
Xconx.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Persist Security Info=False;" & _
"Data Source=" & m_JETDir & "\" & m_JETmdb
Set Xrs = CreateObject("ADODB.Recordset")
Xrs.CursorLocation = adUseServer
End Sub
-----------------------------------------------------------
Sub JETDROP() 'drop connection th MSAccess Database
Set Xconx = Nothing
Set Xcmd = Nothing
Set Xrs = Nothing
End Sub
-------------------------------------------------------------
If you are not sure how to use ADO, I strongly recommend checking:
msdn.microsoft.com/library/ <continue next line>
default.asp?url=/library/en-us/ado270/htm/ <continue next line>
mdmscimicrosoftadoprogrammersreference.asp
-------------------------------------------------------------
I compact and standardize my code with one module to handle inserts, one for deletes and one for updates. It makes commits, rollbacks, and error logging very easy. I pass only an SQL statement, which also simplifies calling stored procedures. Because of the time loss, I don't drop the connection until the application either errors-out or closes normally. Only recordsets are opened and closed.