this code is known to work, just call it with
AdoConnectSecureDB False
'requires a reference set to
'microsoft activex data objects 2.x library
'
'7/6/2006 - ADO CONNECTION TO A ACCESS DB
'PASS [False] for unsecured db
'PASS [True] for a secured db - requires acccount/password
'
Public Sub AdoConnectSecureDB(ByVal SecureDB As Boolean)
'SET DB AND SYSTEM PATHS
Const cMyDBpath = "D:\db2.mdb"
Const cMySysMDW = "D:\System.mdw"
Dim cn As ADODB.Connection, rs As ADODB.Recordset
Dim sCon As String
Dim MyAccount As String
Dim MyPassword As String
Dim errCount As Integer
On Error GoTo erh
Select Case SecureDB
Case Is = False
MyAccount = "Admin"
MyPassword = ""
Case Is = True
MyAccount = "[ACCOUNT]"
MyPassword = "[PASSWORD]"
End Select
'CONNECTION STRING
sCon = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"User ID=" & MyAccount & ";Password=" & MyPassword & ";" & _
"Data Source=" & cMyDBpath & ";" & _
"Persist Security Info=False"
'SECURE DB W/ SYSTEM.MDW?
If SecureDB = True Then sCon = sCon & ";Jet OLEDB:System database=" & cMySysMDW
'CREATE NEW CONNECTION
Set cn = New ADODB.Connection
'OPEN CONNECTION WITH CONNECTION STRING
cn.Open sCon
'CREATE NEW RECORDSET
Set rs = New ADODB.Recordset
'OPEN RECORDSET
'READ/WRITE
rs.Open "TABLE1", cn, adOpenDynamic, adLockOptimistic, adCmdTable
'READ ONLY
'rs.Open "TABLE1", cn, adOpenStatic, adLockOptimistic, adCmdTable
'TRAVERSE RECORDS
rs.MoveFirst
Do While Not rs.EOF
MsgBox rs!model
MsgBox rs!FIELD1
rs.MoveNext
Loop
xit1:
'CLOSE
If rs.State <> adStateClosed Then rs.Close
If cn.State <> adStateClosed Then cn.Close
xit2:
'RELEASE RESOURCES
Set rs = Nothing
Set cn = Nothing
Exit Sub
erh:
MsgBox Err.Description, vbExclamation, Err.Number
errCount = errCount + 1
If errCount = 1 Then Resume xit1 Else Resume xit2
End Sub