?
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
Medium Priority
?
258 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
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 2000 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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

719 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