Folder Date in File Name (1 Viewer)

JDeezy

Registered User.
Local time
Yesterday, 19:24
Joined
Sep 4, 2009
Messages
54
I have some queries importing files from the previous day where instead of the date being in the file name it is in the folder before it. For example C:\Programs\090903\FileName.txt.

I have tried to pull it like this..."C:\Programs\"Format(Date()-1,"yymmdd")"\FileName.txt... still to no avail.

I am really clueless on what to do so if anyone has any ideas it would be greatly appreciated
 

boblarson

Smeghead
Local time
Yesterday, 17:24
Joined
Jan 12, 2001
Messages
32,059
Concatenation is key:

"C:\Programs\" & Format(Date()-1,"yymmdd") & "\FileName.txt"
 

JDeezy

Registered User.
Local time
Yesterday, 19:24
Joined
Sep 4, 2009
Messages
54
I have tried that but for some reason it is saying "You cannot import a text file unless it has one of these extensions: TXT, CSV, TAB, etc." But it is a text file, labeled .txt, and the file is there. So I am just confused about the whole situation.
 

boblarson

Smeghead
Local time
Yesterday, 17:24
Joined
Jan 12, 2001
Messages
32,059
Try building the file path outside of the import statement, so something like:

Dim strPath As String

strPath = "C:\Programs\" & Format(Date()-1,"yymmdd") & "\FileName.txt"

and then use strPath where you were using the other code.

Also, where is FileName coming from? If that is a variable too, then you would need to concatenate it in:

strPath = "C:\Programs\" & Format(Date()-1,"yymmdd") & "\" & FileName & ".txt"
 

JDeezy

Registered User.
Local time
Yesterday, 19:24
Joined
Sep 4, 2009
Messages
54
Yeah same error message with both of the solutions. The file is always constant as New_in.txt it is just the folder date that changes day by day. Im using access 2003 if that might have anything to do with it.
 

boblarson

Smeghead
Local time
Yesterday, 17:24
Joined
Jan 12, 2001
Messages
32,059
What's the entire code you are using?

And are you sure that the path is correct?
 

JDeezy

Registered User.
Local time
Yesterday, 19:24
Joined
Sep 4, 2009
Messages
54
It's confidential so i cant disclose that info but the path is correct. It looks to me like it just stops reading it once it gets to the date and its not picking up the file name tho.
 

boblarson

Smeghead
Local time
Yesterday, 17:24
Joined
Jan 12, 2001
Messages
32,059
Set a breakpoint and step through it using F8 and see what the values are at any one time.
 

Users who are viewing this thread

Top Bottom