G
Guest
While using VBA script to refresh Excel Pivot Tables from Access I am getting
error message "ODBC Microsoft Access Driver Login Failed- The Database has
been placed
in a state by user 'Admin' on machine 'RX1' that prevents it from being
opened or
locked". By pressing alt-tab after the line
oWB.PivotCaches.Item(1).Refresh
I can see that error message is an Excel an error message. I am then
prompted with a Login Window for a "Data Source - MS Access Database" it is
asking me for "Authorization - Login name and Password." I already have Admin
rights on this machine. Nothing I enter works so code gives me "Error 1004 -
Application Defined or object defined Error".
Help please!
Private Sub cmdTest4_Click()
Dim oRs As ADODB.Recordset
Dim oCnn As ADODB.Connection
Dim oApp As Excel.Application
Dim oWB As Excel.Workbook
On Error GoTo ErrorHandler
'Connect to your Access db
Set oCnn = Application.CurrentProject.Connection
'Create your recordset
Set oRs = New ADODB.Recordset
oRs.Open "SELECT * FROM My_Query;", oCnn, adOpenDynamic,
adLockOptimistic, adCmdText
'Create an instance of Excel
Set oApp = New Excel.Application
oApp.Visible = False
'Set oWB = oApp.Workbooks
Set oWB = Workbooks.Open(Filename:="C:\My Documents\refPiv1.xls")
oWB.Worksheets("testSheet4").Activate
'ref ptable
oWB.PivotCaches.Item(1).Refresh
'Clean up ADO Objects
oRs.Close
Set oRs = Nothing
oCnn.Close
Set oCnn = Nothing
'Clean up Excel Objects
oWB.Close SaveChanges:=True
Set oWB = Nothing
oApp.Quit
Set oApp = Nothing
End Sub
error message "ODBC Microsoft Access Driver Login Failed- The Database has
been placed
in a state by user 'Admin' on machine 'RX1' that prevents it from being
opened or
locked". By pressing alt-tab after the line
oWB.PivotCaches.Item(1).Refresh
I can see that error message is an Excel an error message. I am then
prompted with a Login Window for a "Data Source - MS Access Database" it is
asking me for "Authorization - Login name and Password." I already have Admin
rights on this machine. Nothing I enter works so code gives me "Error 1004 -
Application Defined or object defined Error".
Help please!
Private Sub cmdTest4_Click()
Dim oRs As ADODB.Recordset
Dim oCnn As ADODB.Connection
Dim oApp As Excel.Application
Dim oWB As Excel.Workbook
On Error GoTo ErrorHandler
'Connect to your Access db
Set oCnn = Application.CurrentProject.Connection
'Create your recordset
Set oRs = New ADODB.Recordset
oRs.Open "SELECT * FROM My_Query;", oCnn, adOpenDynamic,
adLockOptimistic, adCmdText
'Create an instance of Excel
Set oApp = New Excel.Application
oApp.Visible = False
'Set oWB = oApp.Workbooks
Set oWB = Workbooks.Open(Filename:="C:\My Documents\refPiv1.xls")
oWB.Worksheets("testSheet4").Activate
'ref ptable
oWB.PivotCaches.Item(1).Refresh
'Clean up ADO Objects
oRs.Close
Set oRs = Nothing
oCnn.Close
Set oCnn = Nothing
'Clean up Excel Objects
oWB.Close SaveChanges:=True
Set oWB = Nothing
oApp.Quit
Set oApp = Nothing
End Sub