Article ID: 161016
Article Last Modified on 1/19/2007
Set db = workspace.OpenDatabase(dbname, options, read-only, connect)NOTE: Even though the Options and Read-Only arguments of the OpenDatabase method are documented in Help as being optional arguments, you must provide them when you use the Connect argument. If you use a Connect argument and you do not provide the Options and Read-Only arguments, you receive run-time error 3031 "Not a valid password." This occurs even if the password that you provided in the Connect argument is correct. If you do not need to use a Connect argument, then you can omit the Options and Read-Only arguments.
"MS Access;pwd=<password>"
Sub OpenDB()
Dim db As Database
Dim ws As WorkSpace
Dim rst As Recordset
Set ws = DBEngine.WorkSpaces(0)
Set db = ws.OpenDatabase _
("C:\Program Files\Microsoft Office\Office\Samples\Northwind.mdb", _
False, False, "MS Access;PWD=northwind")
Set rst = db.OpenRecordset("Customers", dbOpenDynaset)
If rst.RecordCount > 0 Then
rst.MoveLast
MsgBox rst!CustomerID
End If
rst.Close
db.Close
End Sub
OpenDB
Additional query words: pwd secure
Keywords: kbhowto kbprogramming KB161016