ACC: "Run-time error '3031': Not a valid password" Error Message

ID: Q192028


The information in this article applies to:


SYMPTOMS

Moderate: Requires basic macro, coding, and interoperability skills.

When you try to open a database programmatically, you may receive the following error message, even though the password is correct:

Run-time error '3031':
Not a valid password.


CAUSE

When you manually set the database password to a password with fourteen characters (the limit), you cannot use that same password to programmatically open the database.


RESOLUTION

Method 1

Do not select a password that is longer than 13 characters if you need to open the database programmatically.

Method 2

When you open the database programmatically, you need only include the first 13 characters of the database password.

To make the example in the "Steps to Reproduce Problem" section work, change the following line of code

   Set db = ws.OpenDatabase _

     ("C:\Program Files\Microsoft Office\Office\Samples\Northwind.mdb", _
     False, False, "MS Access;PWD=FourteenCharac") 
to read as follows:

   Set db = ws.OpenDatabase _

     ("C:\Program Files\Microsoft Office\Office\Samples\Northwind.mdb", _
     False, False, "MS Access;PWD=FourteenChara") 
NOTE: This will programmatically open the Northwind.mdb database even though the password is not correct.


STATUS

Microsoft has confirmed this to be a problem in the products listed at the beginning of this article.


MORE INFORMATION

Steps to Reproduce Problem

  1. Open the sample database Northwind.mdb exclusively.


  2. On the Tools menu, point to Security, and then click Set Database Password.


  3. Type FourteenCharac in the Password and Verify boxes.


  4. Close Northwind.mdb.


  5. Create and open a new database named Test.mdb.


  6. In the Database window, Click Modules. Click New, and then type the following code:


  7. 
        Sub OpenDB()
    
          Dim db As Database
          Dim ws As Workspace
    
          Set ws = DBEngine.Workspaces(0)
    
        ' The default path to Northwind.mdb in Access version 7.0 is
        ' C:\MSOffice\Access\Samples\Northwind.mdb
          Set db = ws.OpenDatabase _
           ("C:\Program Files\Microsoft Office\Office\Samples\Northwind.mdb", _
           False, False, "MS Access;PWD=FourteenCharac")
    
          Set ws = Nothing
          Set db = Nothing
    
        End Sub 
  8. On the View menu, click Debug Window. Type OpenDB, and then press ENTER.


Note that you receive the error message mentioned in the "Symptoms" section.

Steps to Remove the Password from Northwind.mdb

  1. Open the sample database Northwind.mdb exclusively.


  2. Type FourteenCharac in the Enter Database Password box. Click OK


  3. On the Tools menu, point to Security, and then click Unset Database Password.


  4. Type FourteenCharac in the Password box. Click OK


  5. Close the Northwind.mdb database.


Additional query words: wrong invalid incorrect


Keywords          : kbdta MdlProb 
Version           : WINDOWS:7.0,97
Platform          : WINDOWS 
Issue type        : kbbug 

Last Reviewed: May 13, 1999