Trouble Trapping Error

  • Thread starter Thread starter Randy
  • Start date Start date
R

Randy

Access 2000. I cant seem to trap an error on my form. The error is:
"Microsoft Access was unable to append all the data to the table" Ive found
the error number is 10014. I've placed the following code in the on error
event of my form and tried it on the double click event of the control with
no luck. I still get the generic error. Here's the code i've t4ried to
use: Any ideas?...Thanks..Randy

If Err.Number = 10014 Then
Response = acDataErrContinue
MsgBox "These samples may have already been entered in the database.
Select another disk or click yes to continue"
Me.Undo
End If
 
Randy said:
Access 2000. I cant seem to trap an error on my form. The error is:
"Microsoft Access was unable to append all the data to the table"
Ive found the error number is 10014. I've placed the following code
in the on error event of my form and tried it on the double click
event of the control with no luck. I still get the generic error.
Here's the code i've t4ried to use: Any ideas?...Thanks..Randy

If Err.Number = 10014 Then
Response = acDataErrContinue
MsgBox "These samples may have already been entered in the
database. Select another disk or click yes to continue"
Me.Undo
End If

Would you mind posting the rest of the procedure? You don't show the
"On Error" statement, nor the statement label for the error-handler.
 
The error statement is: "Microsoft Access was unable to append all the data
to the table. The contents of fields in 0 records were deleted, and 12
records were lost due to key violations etc." Here is the on error event
of my form: This is all I have..
Private Sub Form_Error(DataErr As Integer, Response As Integer)
If Err.Number = 10014 Then
Response = acDataErrContinue
MsgBox "These samples may have already been entered in the database.
Select another disk or click yes to continue"
Me.Undo
End If
End Sub
 
Randy said:
The error statement is: "Microsoft Access was unable to append all
the data to the table. The contents of fields in 0 records were
deleted, and 12 records were lost due to key violations etc." Here
is the on error event of my form: This is all I have..
Private Sub Form_Error(DataErr As Integer, Response As Integer)
If Err.Number = 10014 Then
Response = acDataErrContinue
MsgBox "These samples may have already been entered in the
database. Select another disk or click yes to continue"
Me.Undo
End If
End Sub

If you're going to use the form's Error event, you need to interrogate
the DataErr argument that is passed to the event procedure:

Private Sub Form_Error(DataErr As Integer, Response As Integer)

If DataErr = 10014 Then
Response = acDataErrContinue
MsgBox _
"These samples may have already been entered " & _
"in the database. Select another disk or " & _
"click yes to continue"
Me.Undo
End If

End Sub

But it would be better to trap the error in the procedure that raises
it. So if you have a procedure that currently looks roughly like this
....

Private Sub cmdAppend_Click()

' ... some code ...

CurrentDb.Execute "Your Append Query", dbFailOnError
' or DoCmd.RunSQL, or DoCmd.OpenQuery

' ... more code ...

End Sub

.... then you would do better to establish error-handling in that
procedure. In that case, you *would* refer to Err.Number to identify
the error. It would look something like this:

Private Sub cmdAppend_Click()

On Error GoTo Err_Handler

' ... some code ...

CurrentDb.Execute "Your Append Query", dbFailOnError

' ... more code ...

Exit_Point:
Exit Sub

Err_Handler:
If Err.Number = 10014 Then
MsgBox _
"These samples may have already been entered " & _
"in the database. Select another disk or " & _
"click yes to continue"
Me.Undo
End If
Resume Exit_Point

End Sub
 
Thanks Dirk, you helped me figure it out..Randy

Dirk Goldgar said:
If you're going to use the form's Error event, you need to interrogate
the DataErr argument that is passed to the event procedure:

Private Sub Form_Error(DataErr As Integer, Response As Integer)

If DataErr = 10014 Then
Response = acDataErrContinue
MsgBox _
"These samples may have already been entered " & _
"in the database. Select another disk or " & _
"click yes to continue"
Me.Undo
End If

End Sub

But it would be better to trap the error in the procedure that raises
it. So if you have a procedure that currently looks roughly like this
...

Private Sub cmdAppend_Click()

' ... some code ...

CurrentDb.Execute "Your Append Query", dbFailOnError
' or DoCmd.RunSQL, or DoCmd.OpenQuery

' ... more code ...

End Sub

... then you would do better to establish error-handling in that
procedure. In that case, you *would* refer to Err.Number to identify
the error. It would look something like this:

Private Sub cmdAppend_Click()

On Error GoTo Err_Handler

' ... some code ...

CurrentDb.Execute "Your Append Query", dbFailOnError

' ... more code ...

Exit_Point:
Exit Sub

Err_Handler:
If Err.Number = 10014 Then
MsgBox _
"These samples may have already been entered " & _
"in the database. Select another disk or " & _
"click yes to continue"
Me.Undo
End If
Resume Exit_Point

End Sub


--
Dirk Goldgar, MS Access MVP
www.datagnostics.com

(please reply to the newsgroup)
 
Back
Top