Opening up a Password protected file using VB

A

Andy Morgan

Please can you help?

I am writing some code that will show what users are using a shared database
and in the code I have to put what file I am looking at so I have put the
path in but the file is password protected and when i run the code it is
telling me that the password is incorrect please can you tell me how I can
enter the password into the code.

Please see example of what I have go so far:-
Sub showUserRosterMultipleUsers()
Dim cn As New ADODB.Connection
Dim cn2 As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim i, j As Long

cn.Provider = "Microsoft.Jet.OLEDB.4.0"
cn.Open "Data Source=V:\EMW\SHLSEMW\Staff Information Database\Staff Info
Database.mdb"

cn2.Open "Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=V:\EMW\SHLSEMW\Staff Information Database\Staff Info
Database.mdb"

Set rs = cn.OpenSchema(adSchemaProviderSpecific, _
, "{947bb102-5d43-11d1-dbdf-00c04fb92675}")

'Output the list of all users in the current database.

Debug.Print rs.Fields(0).Name, "", rs.Fields(1).Name, _
"", rs.Fields(2).Name, rs.Fields(3).Name

While Not rs.EOF
Debug.Print rs.Fields(0), rs.Fields(1), _
rs.Fields(2), rs.Fields(3)
rs.MoveNext
Wend


End Sub

The password is for the Staff Info Database.mdb
 
J

Juan M Afan de Ribera

Hi,

try this way:

Dim cn As ADODB.Connection
Dim rs As New ADODB.Recordset

Set cn = New ADODB.Connection
With cn
.Provider = "Microsoft.Jet.OLEDB.4.0"
.ConnectionString = "Data Source=c:\MyDatabase.mdb"
.Properties("Jet OLEDB:Database Password") = "here_the_db_password"

.Open
End With

'... and so



Saludos,
Juan M Afan de Ribera
[MVP Access]
http://www.mvp-access.com/juanmafan
 

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

Top