Error Trap of "0"

Experts

I have this error display of "0" and I dont want this error msg to show.
I dont know what error it is because the code does what I want it to do.  
I can usually handle an error by defining it with an IF statement.
For some reason I seem to not be able to do the same if the error is 0.
You can see in my error handler I do put an IF error = 0 then exit sub but the code does not exit and still displays the error of 0 msbox.

If an error is 0, is it suppose to be handled like this or maybe there is obviously something else going on? (note that the INSERT code does do what it is suppose to do)


Private Sub Amount_BeforeUpdate(Cancel As Integer)

     On Error GoTo EH  '<-- add this for error handling
 

        Dim strSQL As String
If Not IsNull(Me.Amount) Then
'get an error if I try to save on before update
 'DoCmd.RunCommand acCmdSaveRecord

  strSQL = "INSERT INTO tblLCAmountHistory (fldDate, letterOfCreditID, EndUserID, LCNo, Amount) VALUES (#" & Format(Date, "m\/d\/yyyy") & "#," & Me!ID & "," & Me!EndUserID & ",'" & HyperlinkPart(Me!LCNo, acDisplayText) & "'," & Me!Amount & ")"
  
 
  Debug.Print strSQL
  
  DoCmd.SetWarnings False
  DoCmd.RunSQL strSQL
  DoCmd.SetWarnings True

Else

End If

   
EH:
   If Error = 0 Then
     Exit Sub
   Else
      
     MsgBox "Error: " & Err.Number & ": " & Err.Description
    End If
    

End Sub

Open in new window

untitled.JPG
pdvsaProject financeAsked:
Who is Participating?
 
OklahomaDaveCommented:
You're checking the wrong thing in your error handler. Just check for Err.Number=0 in the If statement and your problem should go away. The way you've written that IF statement, it will always evaluate to FALSE and force the ELSE portion to execute, causing the display of the message box you are experiencing.

Good luck.

0
 
pdvsaProject financeAuthor Commented:
Dave, that was it.  I remember this now. I wrote it down correctly in my word doc full of code but for some reason I keep forgetting to use the "Err.Number"

it works now.

thanks...
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.