When the MDB file has a password and the MDB file is printed directly by Access, the Password dialog box appears, asking for the password. However, to be printed in VB program, you must change the VB program to open the MDB file instructions, otherwise there will be error messages! The following are described in a variety of situations:
1. Open the MDB file using the DAO command: OpenDatabase
To open in a program, the commands are as follows:
Set DB = OpenDatabase (DatabaseName, False, false, "; pwd= password ")
Instance:
Dim DB as Database
Set db = OpenDatabase ("C:\db1.mdb", False, false, "; Pwd=1 ")
To use the Data control, you set the method as follows:
1, set the DatabaseName property (MDB file name/include path)
2, set Connect properties, the preset string "Access" to ";" pwd= password "(excluding double quotes)
3. Set RecordSource Properties
2,
To open an MDB file using the ADO command:
After using ADODC or DataEnvironment, modify the ConnectionString property (attached to ADODC) or the Connectionsource property directly using the Properties window (attached to the DataEnvironment Co Nnection control), the modified method is to add the following parameters after the property:
; Jet oledb:database password= Password
In addition to ADODC and DataEnvironment, you use an ADO control to open an MDB MDB file with a password, and the method of setting the parameters is the same.
3,
To compress a password-coded MDB file: CompactDatabase
Dbengine.compactdatabase "Original MDB file", "New MDB file",,, ";p wd= password"
Examples for example:
Dbengine.compactdatabase "C:\Db1.mdb", "C:\Db2.mdb",,, ";p wd=1"
4,
To fix a password-coded MDB file: repairdatabase
No need to ignore the password set by the MDB file!
Dbengine.repairdatabase "MDB file"
Examples for example:
Dbengine.repairdatabase "C:\Db1.mdb"