Solved

Error Handler Not Working in Access VBA

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

708 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

16 Experts available now in Live!

Get 1:1 Help Now