|
|
Free VB Projects
|
Create MS Access database and lock it with password from VB code |
Description:
This VB project creates a Microsoft Access database and lock it with a specified password.
The database contains no tables (tables can be created either using code or in MS Access).
Keywords:
Microsoft Access database, Create database from VB code, Lock database with password,
Database in VB, Password locked database, lock MS Access database
'Note: This code requires a reference to the DAO object library
Private Sub Command1_Click()
Dim wrkDefault As Workspace
Dim dbsNew As Database
'Get default Workspace.
Set wrkDefault = DBEngine.Workspaces(0)
'Set the database filename
DBFilename = App.Path & "\mydb.mdb"
'Make sure there isn't already a file with the same name of
'the new database file.
If Dir(DBFilename) <> "" Then
MsgBox "File already exists!"
Exit Sub
End If
'Create a new encrypted database with the specified
'collating order.
'lock database with the password 'hello'
Set dbsNew = wrkDefault.CreateDatabase(DBFilename, _
dbLangGeneral & ";pwd=hello;", dbEncrypt)
'Note: Above, you can use (dbEncrypt Or dbVersion25) to specify
'the database version:
'dbVersion10 for Access version 1.0
'dbVersion11 for Access version 1.1
'dbVersion20 for Access version 2.0
'dbVersion25 for Access version 2.5
'dbVersion30 for Access version 3.0
'dbVersion35 for Access version 3.5
'Database versions below 2.5 do not support password locking
dbsNew.Close
End Sub
Return to VB projects
|