[Advanced] VBA Query Errors when Directory Path is Too Long

goldfish

Well-known Member
Joined
Aug 23, 2005
Messages
712
Code:
Sub Repoint_Pivots()
Dim DBDIR As String
Dim PvtItem As PivotItem
DBDIR = ThisWorkbook.Path & "\Databases" 'Storage Place of "Geo.mdb"
 
Sheets("Markets").PivotTables("PivotTable1").SourceData = _
Array("DSN=MS Access Database;DBQ=" & DBDIR & "\Geo.mdb;DefaultDir=" & DBDIR & ";DriverId=25;FIL=MS Access;MaxBufferSize=2048;PageTimeout=5;", _
"SELECT S.State, S.City" & Chr(13) & "" & "" & Chr(10), _
"FROM `" & DBDIR & "\Geo`.Locations S")

I get a type mismatch error on the last line. I think the issue is that the Connection part (the first element of the array) is 266 characters (using the long directory path I currently am testing) which I think is too long... I thought there was a limit of 160 characters or something like that. But I haven't been able to break up the connection part of the array without giving me errors... though it seems like the query part can be broken up mid word and it still works fine as each part of the array is just concatenated back together.

Is it possible to write this to account for long path names?

Thanks,
~Goldfish
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top