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
255 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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

830 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