CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2000
    Posts
    292

    Opening a pasword-protected database

    Good day!

    I have an Access 97 database which I password-protected. How can I open it in my VB code? I have below my code.

    Dim db as Database
    Dim dbPswd as string

    On Error GoTo ShowErr

    dbPswd = "myPswd" ' sample only
    Set db = OpenDatabase(App.Path & "\dbf\myDB.mdb", , , ";pwd=" & dbPswd)
    .......
    .......

    ShowErr:
    Msgbox Err.Number ": " & Err.Description

    I set my password in Access to be "myPswd". When I run my code, as soon as I reach the OpenDatabase statement, I get Error No. 3031 "Not a valid password". What's wrong with my code? If the database is successfully opened with the password, will the database be opened exclusively? Thanks in advance!


  2. #2
    Join Date
    May 1999
    Location
    Slovenia
    Posts
    21

    Re: Opening a pasword-protected database

    Hi !

    You have to set parameter FALSE for Options and ReadOnly. Try like that.

    Dim db as Database
    Dim dbPswd as string

    On Error GoTo ShowErr

    dbPswd = "myPswd" ' sample only
    Set db = OpenDatabase(App.Path & "\dbf\myDB.mdb", FALSE , FALSE , ";pwd=" & dbPswd)
    .......
    .......

    ShowErr:
    Msgbox Err.Number ": " & Err.Description


    Let me know if it works.


  3. #3
    Join Date
    Mar 2000
    Posts
    292

    Re: Opening a pasword-protected database

    Thanks for the reply. Your suggestion worked! If I replace the second False parameter w/ True, does this mean that the database is exclusively opened until a db.Close statement is reached? What if it is one of the tables that I want to exclusively open?


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured