Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Open an MS access table by Visual Basic code

  1. Dec 11, 2006 #1
    Hi,

    I am writing a visual basic databse program, and need a code to open a MS access table which is protected by a password.

    It can open the table without password. I need to protect it by password to prevent someone to open and edit it, but I have got a problem to let the visual basic open it by prompt the password automatically.

    In short, if the table without password, everything works fine, and if the table is set by a password, the program cannot open that table so it displays an error message.

    Please help. Thanks

    Sincerely,
    Mike
     
  2. jcsd
  3. Dec 11, 2006 #2
    If an MS Access database is protected by a password, you can provide the password to the OpenCurrentDatabase method:

    Code (Text):

    oAccess.OpenCurrentDatabase(filepath:="c:\myDatabase.mdb", _
                                Exclusive:=False, _
                                bstrPassword:="MyPassword")
     
    A couple warnings.

    Firstly, the password is case sensitive.

    Secondly, a hacker could read the compiled binary executable and find your password. A simple private key would help, but not prevent.

    Although if the database commands are streamed through a port, attempts to stop a hacker from seeing the password are futile. Unless, of course, MS Access uses a private/public key encryption, which I somewhat doubt.

    This is all assuming that your password isn't worth only a few pretty pennies.
     
    Last edited: Dec 11, 2006
  4. Dec 12, 2006 #3
    Sane,

    Thank you for the help. Could you please explain liltle bit more about this method? How to add this to a Visual Basic 6.0 code?

    I defined this function, and call it from the main form_load(). I changed the path to correct directory and change the password too. It still doesn't work. Sorry, I am not a programmer (EE)

    Thanks a lot

    Mike
     
  5. Dec 12, 2006 #4
    It's quite straightforward, actually. First, find where the method "OpenCurrentDatabase" is being called. For instance, you might find this line somewhere in your code:

    Code (Text):
    oAccess.OpenCurrentDatabase(filepath:="[color=red]c:\myDatabase.mdb[/color]")
    Then add an additional parameter, "bstrPassword", with a value equivilent to the password. The following code turns the above code into an example where the password is thisIsmyPassword ¹:

    Code (Text):
    oAccess.OpenCurrentDatabase(filepath:="[color=red]c:\myDatabase.mdb[/color]", bstrPassword="[color=red]thisIsMyPassword[/color]")
    If this doesn't answer your question, it would help to post your code.

    ¹ Red denotes a variable field.
     
    Last edited: Dec 12, 2006
  6. Dec 18, 2006 #5
    http://msdn.microsoft.com

    msdn is an excellent resource once you know the name of a particular method. There is a full description of exactly what everything does and if you are lucky there are sometimes some quite useful examples.

    The problem of course is finding the name of a method... luckily the tree view on the left will usually lead to some list of all of the methods that are a part of some library.

    Unfortunately the amount and quality of the VB6 help seems to be lowering all of the time... if you need VB.net though it is extremely useful.

    A search for your method's name reveals http://support.microsoft.com/kb/235422/ as the second result (the first: http://msdn2.microsoft.com/en-us/library/aa221388(office.11).aspx is the actual reference for the method).

    Hope this helps.
     
    Last edited: Dec 18, 2006
  7. Jan 9, 2007 #6
    Hi Jheriko,

    Thank you very much. It is so cool. Now, my program is kind of opening a security Access database without prompt user password. However, I am still trying to DISABLE SECURITY WARNING BOX because it blocks the program. If you know about this, please help me some more. Thanks

    Sincerely,
    Mike
     
  8. Jan 17, 2007 #7
    Could you tell me more about this warning box? What is causing it to appear?
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?



Similar Discussions: Open an MS access table by Visual Basic code
Loading...