"On error" within While loop failing

M

Marchand

OK, so I know using an "On error" within a While loop isn't terribly
kosher but I'm interfacing Excel with a realtime data system and the
existence/timing/availability of the key file is unpredictable. So I
have used the following VBA code:

' Work off copy to avoid file collisions
On Error GoTo againAgain:

bTryAgain = True
While bTryAgain = True
FileCopy sFullSrcFileName, sFullFileCopyName
bTryAgain = False
GoTo notAgain
againAgain:
Call addLogMsg("openOrders file conflict: " & Now())
notAgain:
Wend

The issue is that the 'On error' works fine the first time the file
isn't available. The log entry is made and the While loop restarts.
What's fascinating, and deeply annoying, is that the second time
through the loop execution halts at the "FileCopy". Simply halts with
the line highlighted. No warning pop-up, no loop, no thing else --
though an Error 70 has been triggered. The intent of the code is to
keep looping through the While loop until the FileCopy can succeed.
I'm not at all clear why the 'On error' logic stops after just one
error . Any ideas out there?

= M =
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top