Solved

Error Handler Not Working in Access VBA

Posted on 2007-11-29
5
332 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 119

Assisted Solution

by:Rey Obrero
Rey Obrero 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Most if not all databases provide tools to filter data; even simple mail-merge programs might offer basic filtering capabilities. This is so important that, although Access has many built-in features to help the user in this task, developers often n…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

910 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

20 Experts available now in Live!

Get 1:1 Help Now