TransferSpreadsheet acLink in VBA question

PB7

Board Regular
Joined
Mar 1, 2011
Messages
58
All, I have code using TransferSpreadsheet within VBA code.

But, I would like the folder location to vary, depending on the folder's name keyed in by the user into a form. One time, he may need to link to files in Folder1, the next day he would link to Folder2, and so on.

So, trying something here, Access VBA does not like this code:

Do.Cmd.TransferSpreadsheet acLink, acSpreadsheetTypeExcel9, "One", "E:\" & "Forms![SelectForm]![Foldername]" & "\" & "One.xls", True

Access error says this is not a valid path, so obviously, my problem is the Forms![SelectForm]!Foldername] reference.

Would anyone know how to do this? To insert a variable folder name into this VBA code?

Thanks in advance to anyone who can help, thanks.
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Since you can't really see exactly what you're getting and Access isn't happy, try this untested code before your "Do.Cmd" line:
Dim PathFile as string
PathFile = "E:\" & Forms![SelectForm]![Foldername] & "\One.xls"
Debug.Print Path
If the immediate window shows you the entire path and file name, substitute what you've done in your "Do.Cmd" line with "PathFile" and see if it works.
 
Upvote 0
Philaburn, thanks! Trying this solution now, and will let you know if successful.
 
Upvote 0
Phildaburn, your solution works great! VBA code nows reads the folder per the form. Thanks very much.
 
Upvote 0

Forum statistics

Threads
1,224,542
Messages
6,179,421
Members
452,913
Latest member
JWD210

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