Richard
Fri Apr 06 10:52:33 CDT 2007
XP wrote:
> Using Office 2003 and Windows XP;
>
> I have a VBS file that I am using to query an MS-Access DB and retrieve
> some
> data. The MDB is password protected; I get an error on the last line, so I
> know it has to do with the password syntax. Can someone help me out to
> correct the syntax so I can query the DB?
>
> sFullNameSource = "\\myUNC\folder\folder\FileName.mdb"
> Set cn = CreateObject("ADODB.Connection")
> Set rs = CreateObject("ADODB.Recordset")
> cn.Provider = "Microsoft.Jet.OLEDB.4.0;"
> cn.Open "Data Source = " & sFullNameSource & "; Password = 123"
To be safe, I would remove spaces. If that doesn't help, perhaps the 123 is
taken as a number. Try:
sPassword = "123"
cn.Open "DataSource=" & sFullNameSource & ";Password=" & sPassword
Actually, I use:
rs.ActiveConnection = "Microsoft.Jet.OLEDB.4.0;" _
"DataSource=" & sFullNameSource & ";Password=" & sPassword
rs.Source = sQuery
rs.Open
where sQuery is my SQL query and sFullNameSource is the full path and file
name of the mdb. My mdb's are not password protected, so maybe you also need
to specify "User ID=", as in:
rs.ActiveConnection = "Microsoft.Jet.OLEDB.4.0;" _
"DataSource=" & sFullNameSource & ";User ID=" & sUser & ";Password=" &
sPassword
--
Richard Mueller
Microsoft MVP Scripting and ADSI
Hilltop Lab -
http://www.rlmueller.net
--