Pivot cache connection string in current Access database

duanecwilson
05-02-2008, 01:26 PM
I created a WORKING Access database which created workbooks with multiple worksheets and pivot tables using ANOTHER Access database as the datasource. The working code is commented out below. As I said, it worked fine with that code I wanted it all to be in one db. Then I moved everything into the current database and tried to change the connection string accordingly. At this point I received this error:

"ODBC Microsoft Access Driver Login Failed"
"The database has been placed in a state by user 'Admin' on machine 'xxxxx' that prevents it from being opened ore locked."

I am not surprised by this. I probably have the connection string overly complicated, but don't know how to word it now so that it will work with the current DB. My offending code is below. The commented out stuff is what used to work fine. The new is where I attempted to make it right, but it bombs out with the above error on the last statement highlighted in red. I have tried many variations, but it shouldn't be nearly as difficult to use one of the database tables as a dat source then some external one. I have looked everywhere for how to connect to my own database or even if I have to.

Code:

--------------------------------------------------------------------------------


On Error GoTo Except
Set PTcache = xlw.PivotCaches.Add(SourceType:=xlExternal)
' PTcache.Connection = Array(Array("ODBC;DSN=MS Access Database;DBQ=D:\Users\501599284\My Documents\EED Actuals Reports.mdb;DefaultDir=" & _
' "D:\Users\501599284\My Documents;D"), Array("riverId=25;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;"))
PTcache.Connection = Array(Array("ODBC;DSN=MS Access Database;DBQ=" & CurrentDb.Name & ";DefaultDir=" & _
CurrentProject.Path & ";D"), Array("riverId=25;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;")) PTcache.CommandType = xlCmdSql'MUST use an Array function here if string is longer than 255 characters - Excel 2000 issue
'PTcache.CommandText = Array("SELECT GM_FW_Weekly.GeneralManager, GM_FW_Weekly.EmployeeType, GM_FW_Weekly.PandL, ", _
' "GM_FW_Weekly.Platform AS Category, GM_FW_Weekly.PlatformDetail AS Activity, GM_FW_Weekly.FunctionalManager, GM_FW_Weekly.ProgramType, GM_FW_Weekly.Pl", _
' "atformDetail, GM_FW_Weekly.SHOP_ORDER, GM_FW_Weekly.ACTIVITY_NUMBER, GM_FW_Weekly.EMPLOYEE_NAME, GM_FW_Weekly.FW, ", _
' "GM_FW_Weekly.HOUR_TYPE, GM_FW_Weekly.LaborRate, GM_FW_Weekly.Hours, ", _
' "GM_FW_Weekly.Plan, GM_FW_Weekly.PlanByFM, GM_FW_Weekly.Cost, GM_FW_Weekly.Function, GM_FW_Weekly.Heads" & Chr(13) & "" & Chr(10) & _
' "FROM `\\Scgvls01psge\npis1-s2\Weekly Info\Duane\EED Actuals Reports`.GM_FW_Weekly GM_FW_Weekly" & Chr(13) & "" & Chr(10) & "", _
' "WHERE GM_FW_Weekly.GeneralManager LIKE '" & GM & "' ", _
' "ORDER BY GM_FW_Weekly.GeneralManager, GM_FW_Weekly." & "", _
' "EmployeeType, GM_FW_Weekly.PandL, GM_FW_Weekly.Platform, GM_FW_Weekly.PlatformDetail, GM_FW_Weekly.FW")

PTcache.CommandText = Array("SELECT GM_FW_Weekly.GeneralManager, GM_FW_Weekly.EmployeeType, GM_FW_Weekly.PandL, ", _
"GM_FW_Weekly.Platform AS Category, GM_FW_Weekly.PlatformDetail AS Activity, GM_FW_Weekly.FunctionalManager, GM_FW_Weekly.ProgramType, GM_FW_Weekly.Pl", _
"atformDetail, GM_FW_Weekly.SHOP_ORDER, GM_FW_Weekly.ACTIVITY_NUMBER, GM_FW_Weekly.EMPLOYEE_NAME, GM_FW_Weekly.FW, ", _
"GM_FW_Weekly.HOUR_TYPE, GM_FW_Weekly.LaborRate, GM_FW_Weekly.Hours, ", _
"GM_FW_Weekly.Plan, GM_FW_Weekly.PlanByFM, GM_FW_Weekly.Cost, GM_FW_Weekly.Function, GM_FW_Weekly.Heads" & Chr(13) & "" & Chr(10) & _
"FROM GM_FW_Weekly GM_FW_Weekly" & Chr(13) & "" & Chr(10) & "", _
"WHERE GM_FW_Weekly.GeneralManager LIKE '" & GM & "' ", _
"ORDER BY GM_FW_Weekly.GeneralManager, GM_FW_Weekly." & "", _
"EmployeeType, GM_FW_Weekly.PandL, GM_FW_Weekly.Platform, GM_FW_Weekly.PlatformDetail, GM_FW_Weekly.FW")
Set pt = PTcache.CreatePivotTable(TableDestination:="", TableName:="GMPivot")

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum