Open an MS access table by Visual Basic code

AI Thread Summary
To open a password-protected MS Access table using Visual Basic, the OpenCurrentDatabase method can be utilized with the bstrPassword parameter to provide the password directly. It's important to note that the password is case-sensitive and there are security concerns regarding password visibility in compiled binaries. Users have reported success in implementing this method, but issues may arise if the code is not correctly configured. For those struggling with the implementation, it is suggested to ensure the correct syntax is used, specifically adding the bstrPassword parameter to the OpenCurrentDatabase call. Resources like MSDN can provide additional guidance on method usage. Additionally, users have expressed a need to disable security warning prompts that can interfere with program functionality after successfully accessing the database. Further clarification on the nature of these warnings and their triggers is sought to resolve this issue.
Mike Phan
Messages
67
Reaction score
0
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


Mike
 
Technology news on Phys.org
If an MS Access database is protected by a password, you can provide the password to the OpenCurrentDatabase method:

Code:
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:
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
 
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:
oAccess.OpenCurrentDatabase(filepath:="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[/color] ¹:

Code:
oAccess.OpenCurrentDatabase(filepath:="c:\myDatabase.mdb[/color]", bstrPassword="thisIsMyPassword[/color]")

If this doesn't answer your question, it would help to post your code.

¹ Red denotes a variable field.[/size]​
 
Last edited:
Mike Phan said:
Sane,

Could you please explain liltle bit more about this method? How to add this to a Visual Basic 6.0 code?

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 by a moderator:
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


Mike
 
Could you tell me more about this warning box? What is causing it to appear?
 

Similar threads

Back
Top