Access and VB

  • Thread starter Thread starter Chris Huddle
  • Start date Start date
C

Chris Huddle

Does anyone know how to programatically set a password for an Access
Database, preferably in ADO? Thanks! - Chris
 
Hi Chris,

This code will set a password to a previously unprotected Access database:

Dim cnData As ADODB.Connection
Set cnData = New ADODB.Connection
With cnData
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "Data Source=c:\mydatabase.mdb"
.Mode = adModeShareExclusive
.Open
End With

cnData.Execute "ALTER DATABASE PASSWORD mynewpassword NULL"

Regards

Gerard O'Donnell
 
Great code..I needed something like that. Next question, how do you open an
Access database that is password protected>
 
Hi Dennis,

To open a password protected Access database you've got to include the
Password in the Properties collection of the ADO connection.

Dim cnData As ADODB.Connection
Set cnData = New ADODB.Connection

With cnData
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "Data Source=c:\mydatabase.mdb"
.Properties("Jet OLEDB:Database Password") = "existingpassword"
.Mode = adModeShareExclusive
.Open
End With

Regards,

Gerard O'Donnell
 
Thanks. I wasn't sure of the syntax. This will help me a lot in what I'm
working on.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

VB and Access 1
Access Field Types 7
access 8
Export nText as Files 10
Using VB 2008 find out who is using access databae 4
SNMP and VB 2005 1
dbase III, IV, 5 files and ADO 2.0 4
StringConnection 9

Back
Top