I currently have Excel VBA code that connects to an Access database to run a query and returns the results back into Excel. This Excel application is used by many users across the country and is linked to the same Access database on a public drive. The database has sensitive data so it is password protected to prevent users from opening the MDB file outside the application.
However I finding that sometimes users get the following error:
Error Number: -2147467259
Error Description: Could not use ''; file already in use.
I believe that I close the connection after I am done with the query (see code below) so I don't think that is the issue.
After doing some research, it was said that the cause of the error would be if a user has their default open mode in Access to 'Exclusive'. There were suggestions to force Access to be open in Shared mode (instead of Exclusive).
How can I achieve this? It is not a Parameter of the ADO Open Method.
However I finding that sometimes users get the following error:
Error Number: -2147467259
Error Description: Could not use ''; file already in use.
I believe that I close the connection after I am done with the query (see code below) so I don't think that is the issue.
After doing some research, it was said that the cause of the error would be if a user has their default open mode in Access to 'Exclusive'. There were suggestions to force Access to be open in Shared mode (instead of Exclusive).
How can I achieve this? It is not a Parameter of the ADO Open Method.
Code:
'Set destination
Set Location = [AG2]
'Set source
MyConn = "C:\PAT2.mdb"
'Create query
sSQL = "SELECT sg_lookup.salesgroup, sg_lookup.field_nat, sg_lookup.group_dl, sg_lookup.coord_dl, sg_lookup.rsm_dl, sg_lookup.office, sg_lookup.disctrict, sg_lookup.gm, sg_lookup.sd, sg_lookup.vp, sg_lookup.admin, sg_lookup.min_rev FROM sg_lookup WHERE (((sg_lookup.cell_link)=" & Range("sales_dd_link").Value & "));"
strConnect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=P:\Pricing\Databases\PAT.mdw;Persist Security Info=False;Jet OLEDB:System database=P:\Pricing\Databases\System2.mdw Password=pw;User ID=Admin;"
'Create RecordSet
Set Cn = New ADODB.Connection
With Cn
.CursorLocation = adUseClient
.Open strConnect
Set Rs = .Execute(sSQL)
End With
'Write RecordSet to results area
Rw = Location.Column
Col = Location.Row
c = Col
Do Until Rs.EOF
For Each MyField In Rs.Fields
'paste the value in the cell
Cells(c, Rw) = MyField
c = c + 1
Next MyField
Rs.MoveNext
Rw = Rw + 1
c = Col
Loop
Set Location = Nothing
Set Cn = Nothing