I have a VBA query built in excel that runs a SQL query against an Access Database. The connection works when the database is unprotected without a password using the following code:
Set Connection = New ADODB.Connection
Cnct = "Provider=Microsoft.ACE.OLEDB.12.0;"
Cnct = Cnct & "Data Source=" & DBFullName & ";"
Connection.Open ConnectionString:=Cnct
But when I password protect the database and try the same above but with added password condition, it won't connect and I get a "Run-time error -2147217843" message. The code I'm using for this is as follows:
Set Connection = New ADODB.Connection
Cnct = "Provider=Microsoft.ACE.OLEDB.12.0;"
Cnct = Cnct & "Data Source=" & DBFullName & ";"
Cnct = Cnct & "user ID=" & Environ("Username") & ";"
Cnct = Cnct & "password=XXXXXXXXXX;"
Connection.Open ConnectionString:=Cnct
Does anybody know what I am doing wrong here?
admin