Hi Prototype,
I use ADO to connect to an Access 2002 database, here is the code I use
VB Code:
'String used to connect to the SRT database -- this allows for network use in the future
'Keep in module so that only module needs to be changed when database is moved
Public cnSRTDB As String
'main SRT database
Public SRT_DBcn As ADODB.Connection
Public cmdSRT_DB As ADODB.Command
Public Sub Open_SRTDB()
'set connection and open SRT database
Set SRT_DBcn = New ADODB.Connection
cnSRTDB = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & App.Path & "\SRT_DB.mdb; Persist Security Info=False"
SRT_DBcn.Open cnSRTDB
End Sub
Public Sub Close_SRTDB()
'close database and set to nothing
If SRT_DBcn.State <> adStateClosed Then
SRT_DBcn.Close
Set SRT_DBcn = Nothing
End If
End Sub
I have this in a module and call the open and close when I need to. This allows me the flexibility to change the database connection from one place only -- we are planning on migrating to Oracle later.
Hope this helps!