Home > Default > Runtime Error 3031. Not a valid password

Runtime Error 3031. Not a valid password

November 30Hits:0
Advertisement
I am using VB6, DAO connection to connect to Access ACCDB file. The ACCDB file is created with password. But program hit error whenever attempt to open a db connection. The message as below. I have tested the password by directly opening the ACCDB file
in Microsoft Access. Password is correct.
The error message is runtime error 3031. Not a valid password
The code use as below
Sub OpenDB()
 Dim db As DAO.Database
 Dim ws As DAO.Workspace
 Dim rst As DAO.Recordset
 Set ws = DBEngine.Workspaces(0)
 Set db = ws.OpenDatabase("mydata.accdb", False, False, ";PWD=test12345")
 Set rst = db.OpenRecordset("house", dbOpenDynaset)
 If rst.RecordCount > 0 Then
   rst.MoveLast
   MsgBox rst!address
 End If
 rst.Close
 db.Close
End Sub

Answers

Hi Jsl,
Your code works well on my side, I can open a database with password. Below is the sample which I have tested:
Option Compare Database
Sub OpenDB()
 Dim db As DAO.Database
 Dim ws As DAO.Workspace
 Dim rst As DAO.Recordset
 Set ws = DBEngine.Workspaces(0)
 Set db = ws.OpenDatabase("D:\Access Files\StudentDbWithPWD.accdb", False, False, ";PWD=123")
 Set rst = db.OpenRecordset("ClassInfo", dbOpenDynaset)
 If rst.RecordCount > 0 Then
   rst.MoveLast
   MsgBox rst!ClassName
 End If
 rst.Close
 db.Close
End Sub
So, it is strange that it does not work for you. Can you send me a copy of your Access file to my hotmail account:
[email protected]
I will try to reproduce it on my side.
Best Regards,
Bruce Song [MSFT]
MSDN Community Support | Feedback to us
Get or Request Code Sample from Microsoft
Please remember to mark the replies as answers if they help and unmark them if they provide no help.

Read other 9 answers

Tags:

Related Articles

Copyright (C) 2019 wisumpire.com, All Rights Reserved. webmaster#wisumpire.com 14 q. 2.591 s.