[AccessD] A2003+A2010 File Count in a folder

jwcolby jwcolby at colbyconsulting.com
Sat May 7 06:22:41 CDT 2011


Are you sure the stack overflow is occurring in this function?  IOW if you don't do this count do 
you eventually get the stack overflow?

If so then my guess is a follows:

Local variables inside of a function are placed on the stack.  In this case the local variable that 
could be giving you problems is the F as string.  What may be happening is that this F is getting 
extremely long and filling up the stack.  Make F global.  Doing so will force VBA to place the 
variable on the heap which is essentially infinite, and thus the size of F can grow as big as needed.

Can you use the File System Object?  This is an object that represents the file system of the 
computer.  Using that would allow you to directly get the count of files in the directory object. 
Unfortunately in many cases the FSO is not available if tight security has been implemented.  Check 
it out though.

John W. Colby
www.ColbyConsulting.com

On 5/7/2011 5:42 AM, Darren - Active Billing wrote:
> Hi guys
>
> I keep getting stack overflow errors - need help
>
> We are creating XML files via some other process (Not Access) and I just
> want to count them during the process.
>
> I need to do it continually until the desired no of files is reached.
>
> I am building a progress bar around this file creation process and on some
> occasions we build thousands of files and it can take some time.
>
> Of course I could sit there and watch the file count grow in an Explorer
> window. But like I said this process can take ages.
>
> Application.FileSearch won't work in Access 2010 so I can't use that (I have
> a mix of 2003 and 2010 access versions).
>
> Most of the code I have found on the interweb does the job but I eventually
> run into stack overflows.
>
> Here's a sample of one way that does work but eventually it overflows.
>
>
>
> Private Sub f_fileCount(strPathFolder as string)
>
>    Dim f As String
>
>    Dim c As Long
>
>
>
>    f = Dir$(strPathFolder&  "*.xml")
>
>
>
>    Do While Len(f)<>  0
>
>      c = c + 1
>
>      f = Dir$
>
>    Loop
>
>
>
> End sub
>
>
>
> I have also tried the FSO and that too (eventually) gave Stack Overflow
> errors.
>
> I had it in mind to test the file count using the time say every 5-10
> seconds to update the progress bar.
>
> But it looks like this is not going to be possible
>
> Anyone done this sort of thing before? Any pointers?
> Thanks heaps in advance team
> Darren
>



More information about the AccessD mailing list