Link to home
Start Free TrialLog in
Avatar of zimmer9
zimmer9Flag for United States of America

asked on

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?

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

xlFile = Dir


Open in new window

Avatar of Boyd (HiTechCoach) Trimmell, Microsoft Access MVP 2010-2015
Boyd (HiTechCoach) Trimmell, Microsoft Access MVP 2010-2015
Flag of United States of America image

Avatar of kraiven

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.

Avatar of zimmer9


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\"?
Avatar of Boyd (HiTechCoach) Trimmell, Microsoft Access MVP 2010-2015
Boyd (HiTechCoach) Trimmell, Microsoft Access MVP 2010-2015
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial