Solved

Error Handler Not Working in Access VBA

Posted on 2007-11-29
5
336 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

752 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