Solved

Error Handler Not Working in Access VBA

Posted on 2007-11-29
5
333 Views
Last Modified: 2008-02-01
I'm importing a set of CSV files into Access.

My procedure loops through a list of filepaths kept in a table. Some days, some of the files will not exist so I want the code to proceed to the next in the list. I've used On Error Resume Next, On Error GoTo Move_To_Next_File etc - all the usual error handling techniques - but my code still breaks.

I'm using the Scripting FileSystemObject library in this procedure. Some of the source files have "." in the filename (which Access cannot import) so I use FSO's file.copy method to copy the file to a temporary folder under a different name, then import. However, when I encounter a file that does not exist it breaks here:

Set file = FSO.GetFile(filepath)

It will not Resume Next or GoTo the label I specify.
0
Comment
Question by:TimHudspith
5 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 20372824
Have you got your error handling setting switched to Break On All errors?
If so - set it to Break on Unhandled Errors.
(Tools>options, General tab)
0
 

Author Comment

by:TimHudspith
ID: 20372840
It's already set to 'Break on Unhandled Errors'.
0
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 300 total points
ID: 20372922
Is the error coming about beause the file doesn't exist? If so, you could use the FileExists method of the FSO to check first (sorry, don't know much about that library, as I absolutely refuse to use it since it can be entirely disabled by network admins or antivirus software).
0
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 200 total points
ID: 20373063
<My procedure loops through a list of filepaths kept in a table>
If there is a particular reason for this,
try using

dim xFile
xfile=dir(filePath &"\*.csv")
while xFile<>""
         if  not Isnull(dlookup(filepath &"\"& xfile,"TableName")) then
               'import the file
             else
               'whatever
          end if

         xFile=dir
wend
0
 

Author Comment

by:TimHudspith
ID: 20382048
LSMConsuulting: Yes, it breaks because the file does not exist. I completely missed the FileExists method - I'll use it for now. Good to know about the FSO shortcomings also.

Capricorn1 - I haven't come across dlookup(). Thanks.
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…

803 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