Article ID: 163002
Article Last Modified on 2/12/2007
DbEngine.SystemDB="C:\MyApplication\system.mdw"
Database Name: Secure AccessDB.mda Database Table: Name Table Field: Last Name User Name: NewAdmin Password: NewAdmin Member of: Admins Group Permissions: AllTo create this secured database, refer to the chapter in the Access documentation listed in the REFERENCES section of this article. Alternatively, you could secure one of the sample applications using the same instructions and make the appropriate changes in the code.
Control Name Property Value
---------------------------------------------------------------------
Label Label1 Caption User Name:
Height 255
Left 120
Top 120
Width 855
Text Box Text1 Caption <Blank>
Height 285
Left 1080
Top 120
Width 1455
Command Button Command1 Height 372
Left 2760
Top 120
Width 1572
Label Label2 Caption Password:
Height 255
Left 120
Top 480
Width 855
Text Box Text2 Caption <Blank>
Height 285
Left 1080
Top 480
Width 1455
Label Label3 Caption <Blank>
Height 255
Left 120
Top 840
Width 4335
Private Sub Command1_Click()
Dim MyWorkspace As Workspace
Dim SecuredDB As String
Dim slUserName As String
Dim slPassword As String
Dim db As Database
Dim rs As Recordset
'Set the location of the system database
DBEngine.SystemDB = _
"C:\Projects\Secured Database Article\system.mdw"
'Create a new workspace object
slUserName = Text1.Text
slPassword = Text2.Text
Set MyWorkspace = DBEngine.CreateWorkspace("New", _
slUserName, _
slPassword)
'Open the database
SecuredDB = _
"C:\Projects\Secured Database Article\Secure AccessDB.mdb"
Set db = DBEngine.Workspaces("New").OpenDatabase(SecuredDB)
Set rs = db.OpenRecordset("Name", dbOpenDynaset)
rs.MoveFirst
Label3.Caption = _
"The first record is " & rs.Fields("LastName").Value
'Close the recordset and the database
rs.Close
db.Close
End Sub
161016 : INF: Using DAO to Open Password-Protected Database (7.0/97)
Additional query words: Access
Keywords: kbhowto KB163002