Solved

How to determine the total number of XLS files in a directory so that I can display the progress when looping through the XLS files in a particular directory?

Posted on 2011-03-07
4
254 Views
Last Modified: 2012-05-11
I am developing an Access application using Access 2003 with an MDB type file.

I am working on a routine to import ALL XLS files that reside within a particular directory in the following code section. I am only showing a SNIPPET of code from this particular routine in the code section.

This routine reads 1 or more XLS files from the directory named
xlPath = Directory() & "\ManualBanks\"
and processes these XLS files 1 at a time USING A LOOP.

Is there a way to INITIALLY get a record count of how many XLS files reside in directlry
xlPath = Directory() & "\ManualBanks\" and then I can display a label caption
Me!lblManualBanks.Caption =
and inform the user during the 1st loop that I am processing the 1st bank out of the total number of banks. Assuming there are 21 XLS files in total, then the 21st and last time through the loop, I would display, via the label caption, that I am processing the 21st bank out of 21 banks,

Thus, I could have a variable, let's call it BankCurrentCounter, that holds the current iteration of the number of times through the loop and another varabile named BankTotalCounter that contains the total number of XLS files in directory Directory() & "\ManualBanks\".
This way I could tell the user that I am processing BankCurrentCounter out of BankTotalCounter so that the user has an idea how long the process will take to loop through all the banks in directory Directory() & "\ManualBanks\".
.






 

Private Sub Command44_DblClick(Cancel As Integer)
On Error Resume Next

xlPath = Directory() & "\ManualBanks\"

xlFile = Dir(xlPath & "*.xls")

If xlFile = "" Then
   MsgBox ("You need at least 1 XLS file in the Manual Banks folder")
   Exit Sub
End If   

While xlFile <> ""
    filenm = xlPath & xlFile.

Me!lblManualBanks.Caption = "Imported Bank Number " & bankNum
Me.Repaint

xlFile = Dir

Wend

Open in new window

0
Comment
Question by:zimmer9
  • 2
4 Comments
 
LVL 21
ID: 35058940
0
 
LVL 3

Expert Comment

by:kraiven
ID: 35058974
Hi zimmer9,

you're almost there as it happens. I don't believe there is a FileCount function as such so what you need to do is call the function, loop through all the files and increment a counter as you do so. Return the counter and that is your FileCount function.

0
 

Author Comment

by:zimmer9
ID: 35059197
How can I initially read the directory xlPath = Directory() & "\ManualBanks\"
to retrieve the TOTAL number of XLS files AND then start all over AND individually process all the files in the directory xlPath = Directory() & "\ManualBanks\"?
0
 
LVL 21

Accepted Solution

by:
Boyd (HiTechCoach) Trimmell, Microsoft Access MVP earned 500 total points
ID: 35059792
If you want to use the Dir command and tn the FSO like in the example I liked to then try:

Private Sub Command44_DblClick(Cancel As Integer)
On Error Resume Next


Dim lngFileCount as long



xlPath = Directory() & "\ManualBanks\"


' get first file
xlFile = Dir(xlPath & "*.xls")

If xlFile = "" Then
   MsgBox "You need at least 1 XLS file in the Manual Banks folder"
   Exit Sub
End If   

lngFileCount = 0 

While xlFile <> ""

   lngFileCount = lngFileCount + 1   
   xlFile = Dir

Wend

Msgbox "You are about to import " & lngFileCount   & " files." 


' get first file
xlFile = Dir(xlPath & "*.xls")



While xlFile <> ""
    filenm = xlPath & xlFile.

Me!lblManualBanks.Caption = "Imported Bank Number " & bankNum
Me.Repaint

xlFile = Dir

Wend

Open in new window

0

Featured Post

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question