Check out http://www.codeoftheweek.com/netmon for a great Internet performance monitor.
Password Protected Access databases from VB. The complete source code appears near the end of this issue. Be sure not to miss it!
One feature that has been requested many times lately is the ability to create and open password protected databases. This issue shows how to create a password protected Microsoft Access database from Visual Basic. You simply set a few properties and call the CreateDatabase method and it will automatically create a database that requires a password for opening. This is a great feature to keep Microsoft Access users from messing with your Visual Basic created Access databases.
In an upcoming issue we will show how to password protect certain queries and tables by using the Group and User features of Access. If you are interested in this topic, please email us at email@example.com . We will also show how to password protect an existing database. If you are interested in this topic email us at firstname.lastname@example.org
If you have any questions about using this class, let us know at email@example.com
Public DatabaseName As String
The fully qualified database name to be opened or created.
Public DatabasePassword As String
The password used to open or create the database.
Public Property Let SystemDatabase(sSystemDatabase As String)
The fully qualified path name to the workgroup information file. This file is called system.mdw by default. On a single user system it is often stored in the Windows system directory. In a network environment you probably want to put this file in a shared location for all users to access.
Public Property Get WorkspaceName() As String Public Property Let WorkspaceName(sWorkspaceName As String)
The name of the workspace. This can be any string you would like. The default is DBPassword.
Public Property Get Username() As String Public Property Let Username(sUsername As String)
The username to use when creating the workspace. This is typically Admin if you have not yet defined additional users in Microsoft Access. In an upcoming issue we will discuss how to add, edit and delete users.
Public Property Get Password() As String Public Property Let Password(sPassword As String)
The password to use when creating the workspace. This is typically a blank string until you change it in Microsoft Access. In an upcoming issue we will discuss how to add, edit and delete users.
Public Property Get WorkspaceType() As WorkspaceTypeEnum Public Property Let WorkspaceType(sWorkspaceType As WorkspaceTypeEnum)
The type of workspace to create. This class currently supports the dbUseJet workspace type. We will try to cover the dbUseODBC type in a future issue.
Public Sub CreateDatabase()
Creates a database specified by the properties set above. If the database already exists you will get an error raised back to the caller.
Public Function OpenDatabase() As Database
Opens a database specified by the properties set above. This function returns a database object you can use with most other objects in Visual Basic.
See specific details for each property and method.
Below is an example of how this function works. It will create a database called e:\temp\password.mdb with a password of 'good'. It assumes this database does not already exist.
Dim dbu As New cDBPassword Dim db As Database On Error Goto Handler ' Point to the workgroup file. If you are not sharing the database this is not ' necessary. dbu.SystemDatabase = "c:\windows\system\system.mdw" ' In the next week or so we will discuss how to add additional users to ' the system. dbu.Username = "admin" dbu.Password = "" ' Set the appropriate properties for the database name and password dbu.DatabaseName = "e:\temp\password.mdb" dbu.DatabasePassword = "good" ' create the database with a password dbu.CreateDatabase ' open password protected database. Set db = dbu.OpenDatabase Exit Sub Handler: MsgBox Err.Description
To see the source code for this issue you must be a subscriber to Code of the Week. If you are a subscriber the source code is available at the following address: http://www.codeoftheweek.com/membersonly/bi/0086.html