Open an MS access table by Visual Basic code

In summary: Since the program is trying to access a protected MS Access database, the warning box appears to indicate that the user's password is not strong enough. You might be able to disable the box by finding the appropriate code in your project and changing the value of the "Exclusive" property to "False".
  • #1
Mike Phan
67
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
  • #2
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:
  • #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
 
  • #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:
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:
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:
  • #5
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:
  • #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


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

FAQ: Open an MS access table by Visual Basic code

How do I open an MS Access table using Visual Basic code?

To open an MS Access table using Visual Basic code, you can use the OpenRecordset method. This method allows you to specify the name of the table and the type of access you want (read-only, read-write, etc.). For example, the code Set myTable = CurrentDb.OpenRecordset("TableName", dbOpenDynaset) will open the table TableName in a dynamic recordset that allows for both reading and writing of data.

How do I specify a specific record in an MS Access table using Visual Basic code?

You can specify a specific record in an MS Access table using the FindFirst method. This method allows you to specify a criteria to search for, such as a specific value in a certain field. For example, the code myTable.FindFirst "ID = 123" will find the first record in the table where the ID field has a value of 123.

How do I add a new record to an MS Access table using Visual Basic code?

To add a new record to an MS Access table using Visual Basic code, you can use the AddNew method. This method allows you to enter data into the new record and then save it to the table. For example, the code myTable.AddNew followed by myTable("FieldName") = "New Value" and myTable.Update will add a new record to the table and populate the FieldName field with the value New Value.

How do I update an existing record in an MS Access table using Visual Basic code?

To update an existing record in an MS Access table using Visual Basic code, you can use the Edit method. This method allows you to make changes to the current record and then save those changes to the table. For example, the code myTable.Edit followed by myTable("FieldName") = "Updated Value" and myTable.Update will make changes to the current record in the table and update the FieldName field with the value Updated Value.

How do I close an MS Access table using Visual Basic code?

To close an MS Access table using Visual Basic code, you can use the Close method. This method will close the table and release any resources associated with it. For example, the code myTable.Close will close the myTable recordset and release any resources that were being used.

Similar threads

Replies
14
Views
32K
Replies
1
Views
1K
Replies
6
Views
3K
Replies
16
Views
4K
Replies
4
Views
8K
Replies
10
Views
2K
Back
Top