473,473 Members | 1,818 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

loop through a directory and find the most recently created file

1 New Member
Hi, I am new to Access/VBA can anyone help?

I have a form with a button that runs a macro. I have been using the TransferText action within the macro to import a text file, from a specific directory into an Access table. The macro then runs a couple of queries to re-format the data and prints a report. It then exports the data back into a text file with a new name, to a different directory and deletes the table created in Access. This works very well if the name of the text file is the same each time, but unfortunately the name of text file changes each time it is created. Unfortunately I have no control over the naming of the files.

An example of file names in the directory is:-

00100transfer.txt,
00101transfer.txt,
00102transfer.txt etc…

I need to be able to tell the macro to pick up the most recently created file in the directory. The sequence number part of the file is incremental, so the most recent file will always have the highest sequence number.

I really don’t know where to start to so any help would be much appreciated.

Thanks in advance.
Oct 23 '07 #1
1 3128
Rabbit
12,516 Recognized Expert Moderator MVP
Here's code I've used before to list files. You can chop it up and modify it to do what you need.
Expand|Select|Wrap|Line Numbers
  1. Function Check()
  2. With Application.FileSearch
  3.     Dim length As Integer
  4.     length = Len(Application.CurrentProject.path) + 10
  5.     .NewSearch
  6.     .LookIn = Application.CurrentProject.path & "\Exports\"
  7.     .SearchSubFolders = False
  8.     .FileName = "CDCR " & Me.OpenArgs & " Export"
  9.     .MatchTextExactly = False
  10.     .FileType = msoFileTypeDatabases
  11.  
  12.     If .Execute() > 0 Then
  13.         Dim i As Integer
  14.         Dim Files As String
  15.         Files = "'" & Mid(.FoundFiles(1), length) & "'"
  16.         For i = 2 To .FoundFiles.Count
  17.             Files = Files & ";'" & Mid(.FoundFiles(i), length) & "'"
  18.         Next i
  19.         FileList.RowSource = Files
  20.     Else
  21.         FileList.RowSource = "'No Files Found.'"
  22.     End If
  23. End With
  24. End Function
  25.  
Oct 23 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Stephen Horne | last post by:
Just recently I decided I want to make use of my ISP freebie webspace. In order to make that easier, I'd like to be able to automatically synchronise an FTP file/folder heirarchy with one on my...
6
by: o'seally | last post by:
solaris/linux admins/rookie_developers that battle with this error are probably all frustrated when it happens. i bet you're also somehow frustrated by this seemingly unsolvable error :-) ...take...
11
by: Etienne Charland | last post by:
Hi, I have a solution containing 6 C# projects; 1 WinForms project and 5 class libraries. I didn't have any problems until recently. I added a new project containing reports. I am using...
2
by: Jon Ballinger | last post by:
This is a problem that has recently sprung up. Basically when I build (or rebuild) my solution, dot.net dev studio will go through the motions, and appear to create everything, but there will be no...
4
by: Jerry | last post by:
I'm having just a bit of trouble wrapping my brain around the task of working with folders that are above the site's root folder. I let users upload photos (.jpg/.gif files) which can...
51
by: Tony Sinclair | last post by:
I'm just learning C#. I'm writing a program (using Visual C# 2005 on WinXP) to combine several files into one (HKSplit is a popular freeware program that does this, but it requires all input and...
4
by: Tim | last post by:
Can someone please tell me how I can get the last file added to a directory ( I am assuming it is a file attribute). I have built a text parsing application. Right now I have to manually get the...
0
by: ping235 | last post by:
Recently, i am busying myself on a project that support both the Full ..NET Framework 2.0 and .NET Compact Framework 2.0, with the same set of c# code, but have different project properties and...
13
by: Andrew | last post by:
Hi I was wondering if there is anyway with XML RPC to send a string of text from the server to the client with out calling return thus breaking my loop for example def somefunc(): for...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.