Getting the filename of the latest file and import to table

dhen21dx

Board Regular
Joined
May 10, 2013
Messages
166
Hello

I need a help how can i get the filename of the latest file in a folder, cause i need to import it in the access table.
 

Excel Facts

Why does 9 mean SUM in SUBTOTAL?
It is because Sum is the 9th alphabetically in Average, Count, CountA, Max, Min, Product, StDev.S, StDev.P, Sum, VAR.S, VAR.P.
You could use FileDateTime() function
MS Access: FileDateTime Function

in conjunction with the DIR() function to look through all the files, and store the name of the highest date and time.?

How many files are we talking about.?

I would normally have had the file go into an import folder, then move/delete it after being imported?

You could try find latest file vba - Google Search
 
Upvote 0
You could use FileDateTime() function
MS Access: FileDateTime Function

in conjunction with the DIR() function to look through all the files, and store the name of the highest date and time.?

How many files are we talking about.?

I would normally have had the file go into an import folder, then move/delete it after being imported?

You could try find latest file vba - Google Search
FileDateTime function uses the filename, however, filename is dynamic as have dates or extra character within. Just check the second link and i think this is function VBA for excel.
 
Upvote 0
There is more than one link there?
My thoughts were to check each file with the DIR and pass that filename returned to the FiledateTime function and if greater than the one stored, store that name?

The second link in the Google search actually mentioned VBA Access and asks exactly the same question??? :(
Having looked at it, is is using the method I suggested?
 
Upvote 0
I have to wonder if everyone is on the same page. What constitutes the "latest" file - it's create date? last modified date? A date that's part of the file name? I suspect the latter:
filename is dynamic as have dates or extra character within
@dhen21dx I think you need to clarify, and some examples of file names and you explaining which of those is the "latest" would help.
 
Upvote 0
I have to wonder if everyone is on the same page. What constitutes the "latest" file - it's create date? last modified date? A date that's part of the file name? I suspect the latter:

@dhen21dx I think you need to clarify, and some examples of file names and you explaining which of those is the "latest" would help.
The latest file refers to system modified date of the file, filename also includes date like filename20210708, filename20210709…
 
Upvote 0
Then I'd say you have your answer in that you use that function in code to find the file with the latest modified date. The function is not an Excel function just because you read it on an Excel website. What you don't want to do is store the file itself in an Access db. Store the path instead and retrieve it from the folder when necessary.
 
Upvote 0

Forum statistics

Threads
1,215,339
Messages
6,124,365
Members
449,155
Latest member
ravioli44

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