wildcard in url, before and after (1 Viewer)

2wistd

Registered User.
Local time
Today, 14:01
Joined
Jan 17, 2013
Messages
66
I'm trying to add a spreadsheet from a folder using wildcards by just looking for a number in the file name.

strPath = "C:\Training\"
strFile = strPath & "*" + "(ZZ131008)" + "*.xls"
DoCmd.TransferSpreadsheet acImport, , "Training1", strFile, , ""

I get a response saying it cannot find the file and it shows the * in the path it cannot find. How can I make it find the right file?
There are more files in the folder and the (ZZ131008) defines that course, I'd like to reuse the code for the other courses too.
 

jdraw

Super Moderator
Staff member
Local time
Today, 17:01
Joined
Jan 23, 2006
Messages
15,394
Have you considered using the FileDialog

You can set this up to look for specific file extensions (.xls), but you'd still have to select the one you want.

Here's a sample from Allen Browne for getting filenames into a table or listbox. You may be able to adapt it??
Not sure exactly what you want to happen.
 

Mile-O

Back once again...
Local time
Today, 22:01
Joined
Dec 10, 2002
Messages
11,316
Other alternative is to use the FileSystemObject, loop through the files at the location, and do an IF...THEN...ELSE... to test if a file name is LIKE.
 

2wistd

Registered User.
Local time
Today, 14:01
Joined
Jan 17, 2013
Messages
66
Seems as a combination of both suggestions would probably be best. I used Allen Browns method, but the list has the whole file path in it, impractical for the user to see the whole path and select what they want.

Need to figure out a way to rename those files. Doing my research on FileSystemObject, but not getting much further.
 

Users who are viewing this thread

Top Bottom