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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

762 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now