Error handler runs all the time?

  • Thread starter Thread starter Dale
  • Start date Start date
D

Dale

This is probably really simple, but I can't figure why this error handler
runs even without an error being detected (or I can't see one in debug). If
I remark out the On Error routine, the code runs fine i.e. no errors. With
Error handling on, I get the message box pop up "No files for
import"...which means to me something triggered the error handler but all is
well..data has been imported into the temp tblPI_New_Data and the append to
the SitePI table has run.
What am I missing?
TIA...msAccess 97

Function ImportClean()

On Error GoTo ImportError

DoCmd.RunSQL "INSERT INTO SitePI ( [DATE], [SITE], [Job], [JobCount] ) " _
& "SELECT tblPI_New_Data.DATE, tblPI_New_Data.SITE, tblPI_New_Data.Job,
tblPI_New_Data.JobCount " _
& "FROM tblPI_New_Data " _
& "WHERE ((Not (tblPI_New_Data.Job) Is Null) AND (Not
(tblPI_New_Data.JobCount) Is Null));"

ImportError:
MsgBox "No files for import"
Exit Function

End Function
 
Your Exit Function needs to be *above* the error handler.

Otherwise the procedure just continues on down through the error handler
after the earlier lines.
 
Ahh..thanks..I've doing this wrong for I don't know how many times now...
<embarrassed>

Allen Browne said:
Your Exit Function needs to be *above* the error handler.

Otherwise the procedure just continues on down through the error handler
after the earlier lines.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Dale said:
This is probably really simple, but I can't figure why this error handler
runs even without an error being detected (or I can't see one in debug).
If I remark out the On Error routine, the code runs fine i.e. no errors.
With Error handling on, I get the message box pop up "No files for
import"...which means to me something triggered the error handler but all
is well..data has been imported into the temp tblPI_New_Data and the
append to the SitePI table has run.
What am I missing?
TIA...msAccess 97

Function ImportClean()

On Error GoTo ImportError

DoCmd.RunSQL "INSERT INTO SitePI ( [DATE], [SITE], [Job], [JobCount] ) "
_
& "SELECT tblPI_New_Data.DATE, tblPI_New_Data.SITE, tblPI_New_Data.Job,
tblPI_New_Data.JobCount " _
& "FROM tblPI_New_Data " _
& "WHERE ((Not (tblPI_New_Data.Job) Is Null) AND (Not
(tblPI_New_Data.JobCount) Is Null));"

ImportError:
MsgBox "No files for import"
Exit Function

End Function
 
Back
Top