You are currently offline, waiting for your internet to reconnect

You may receive a "Not a valid password" error message when you try to open a password-protected Access database

Support for Office 2003 has ended

Microsoft ended support for Office 2003 on April 8, 2014. This change has affected your software updates and security options. Learn what this means for you and how to stay protected.


This article applies only to a Microsoft Access database (.mdb).

Moderate: Requires basic macro, coding, and interoperability skills.
SYMPTOMS
When you set a database password for a Microsoft Access database, and then you try to open the Access database, you may not be able to open the Access database successfully. You may receive the following error message:
Not a valid password.
This problem may occur even when you are sure that you have entered the correct database password.
CAUSE
This problem occurs when the database password ends with a backslash character (\).
WORKAROUND
You can avoid this problem when you first create your Access database. You must make sure that the database password for your Access database does not end with a backslash character (\). However, if you have already set the database password for your Access database, and the database password ends with a backslash character (\), you cannot open your Access database. To recover your Access database, import the database objects from your Access database to a newly created Access database. To do this, follow these steps.

Note The sample code in this article uses Microsoft Data Access Objects. For this code to run correctly, you must reference the Microsoft DAO 3.6 Object Library. To do so, click References on the Tools menu in the Visual Basic Editor, and make sure that the Microsoft DAO 3.6 Object Library check box is selected.

You must also make sure that no reference to Microsoft ActiveX Data Objects is selected in the References dialog box.
  1. Start Access.
  2. Create a new Access database that is named RecoveredDB.mdb.
  3. In the Database window, click Modules, and then click New.
  4. Type or paste the following sample code in the module window:
    Option Compare DatabaseOption ExplicitPublic Function ImportDb(strPath As String) As BooleanOn Error Resume NextDim db As Database 'Database to import.Dim td As TableDef 'Table definitions in the database.Dim strTDef As String 'Name of the table or the query to import.Dim qd As QueryDef 'Query definitions in the database.Dim doc As Document 'Documents in the database.Dim strCntName As String 'Document container name.Dim x As Integer 'For looping.Dim cntContainer As Container 'Containers in the database.Dim strDocName As String 'Name of the document.Dim intConst As IntegerDim cdb As Database 'Current database.Dim rel As Relation 'Relation to copy.Dim nrel As Relation 'Relation to create.Dim strRName As String 'Copied relation's name.Dim strTName As String 'Relation table name.Dim strFTName As String 'Relation foreign table name.Dim varAtt As Variant 'Attributes of the relation.Dim fld As Field 'Field(s) in the relation to copy.Dim strFName As String 'Name of the field to append.Dim strFFName As String 'Foreign name of the field to append.'Open the database that contains objects to import.Set db = DBEngine.Workspaces(0).OpenDatabase(strPath, False, False, "MS Access;PWD=<Your database password>")'Import tables from the specified Access database.For Each td In db.TableDefsstrTDef = td.NameIf Left(strTDef, 4) <> "MSys" ThenDoCmd.TransferDatabase acImport, "Microsoft Access", strPath, acTable, _strTDef, strTDef, FalseEnd IfNext'Import queries.For Each qd In db.QueryDefsstrTDef = qd.NameDoCmd.TransferDatabase acImport, "Microsoft Access", strPath, acQuery, _strTDef, strTDef, FalseNext'Copy relationships to the current database.Set cdb = CurrentDbFor Each rel In db.RelationsWith rel'Get the properties of the relation to copy.strRName = .NamestrTName = .TablestrFTName = .ForeignTablevarAtt = .Attributes'Create a relation in the current database with the same properties.Set nrel = cdb.CreateRelation(strRName, strTName, strFTName, varAtt)For Each fld In .FieldsstrFName = fld.NamestrFFName = fld.ForeignNamenrel.Fields.Append nrel.CreateField(strFName)nrel.Fields(strFName).ForeignName = strFFNameNextcdb.Relations.Append nrelEnd WithNext'Loop through the containers and import all documents.For x = 1 To 4Select Case xCase 1strCntName = "Forms"intConst = acFormCase 2strCntName = "Reports"intConst = acReportCase 3strCntName = "Scripts"intConst = acMacroCase 4strCntName = "Modules"intConst = acModuleEnd SelectSet cntContainer = db.Containers(strCntName)For Each doc In cntContainer.DocumentsstrDocName = doc.NameDoCmd.TransferDatabase acImport, "Microsoft Access", strPath, intConst, _strDocName, strDocName'Debug.Print strDocName'for debugging will list document names in the Debug window.Next docNext x'Clean up variables to recover memory.Set fld = NothingSet nrel = NothingSet rel = NothingSet cdb = NothingSet td = NothingSet qd = NothingSet cntContainer = Nothingdb.CloseSet db = Nothingmsgbox "The database has been imported successfully."ImportDb = TrueEnd Function	
    Note Before you run this sample code, replace <Your database password> in the sample code with the password that you have set for your Access database.
  5. On the View menu, click Immediate Window.
  6. In the Immediate window, type the following command line, and then press ENTER:
    ?ImportDb("<Full path of your Access database>")
    After the sample code runs successfully, you can use the new Access database that is named RecoveredDB.mdb instead of your old Access database.
MORE INFORMATION

Steps to reproduce the problem

  1. Start Access.
  2. Create a new Access database that is named TestDB.mdb.
  3. On the Tools menu, point to Security, and then click Set Database Password.
  4. In the Set Database Password dialog box, type password\ in the Password box and in the Verify box.
  5. Click OK.
  6. Close the new Access database that is named TestDB.mdb.
  7. Open the new Access database that is named TestDB.mdb.
  8. In the Password Required dialog box, type password\ in the Enter database password box, and then click OK.

    You receive the error message that is mentioned in the "Symptoms" section even when the database password is entered correctly.
STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.
REFERENCES
For additional information, click the following article numbers to view the articles in the Microsoft Knowledge Base:
209953 How to use the OpenDatabase method to open password-protected databases
162979 "Not a valid password" error when database password contains "\"
ACC2000 ACC2002 ACC2003 DB PWD
Properties

Article ID: 838593 - Last Review: 09/17/2011 09:17:00 - Revision: 4.0

  • Microsoft Office Access 2003
  • Microsoft Access 2002 Standard Edition
  • Microsoft Access 2000 Standard Edition
  • kbvba kbprogramming kbdao kbdatabase kberrmsg kbprb KB838593
Feedback