I'm currently trying to connect to 2 separate .mdb file and perform an INNER JOIN.
So, I have 2 .mdb (Sample1.mdb & Sample2.mdb). Both are password protected.
When I tried to connect, it showed an error stating that "it's already opened exclusively by another user, or you need permission...".
Did the error occurred because I did not insert the password property in this statement? If yes, how do I insert password property into this statement?
[Excel 8.0;HDR=YES;IMEX=2;DATABASE=" & Application.ActiveWorkbook.Path & "\Sample1.mdb]?
Here's my entire sample code:
Dim Conn As ADODB.Connection
Dim resultSet As ADODB.Recordset
Set Conn = New ADODB.Connection
sqlStatement = "SELECT * FROM [Excel 8.0;HDR=YES;IMEX=2;DATABASE=" &
Application.ActiveWorkbook.Path & "\Sample1.mdb].[SampleData$] a INNER JOIN
[Excel 8.0;HDR=YES;IMEX=2;DATABASE=" & Application.ActiveWorkbook.Path &
"\Sample2.mdb].[SampleInfo$] b ON a.Index = b.Index WHERE a.idCode = 2"
With Conn
.Provider = "Microsoft.ACE.OLEDB.12.0"
.ConnectionString = Application.ActiveWorkbook.Path + "\Sample2.mdb"
.Properties("Jet OLEDB:Database Password") = "password"
.Open
Set resultSet = .Execute(sqlStatement)
End With