Error handling

A

am

I have added a Duplicate record button on my form created
using the wizard. When I use it I get a run time error
3022, "duplicate records..........". because ther is some
other code on my form that is saving the record before I
get a chance to change the primary Key field. I know this
is not a clean way to address this but how can I add code
such that if Error=3022 I display a custom message or
ignore it altogether or can somone give me a suggestion on
a better solution. My code(which someone helped me with)
is:
Private Sub MembraneType_AfterUpdate()
Dim strARG As String
Dim strSQL As String
Dim DocName As String
Dim LinkCriteria As String

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, ,
acMenuVer70

If MembraneType = "Other:" Then
strARG = "Membrane Type , SELECT OtherMembraneType as
OtherDescription FROM tblMEA where [MEAnumber] ='" &
MEAnumber & "';"
DocName = "frmOtherDescription"
DoCmd.OpenForm DocName, , , LinkCriteria, , , strARG
Else
strSQL = "UPDATE tblMEA SET OtherMembraneType = null
where [MEAnumber] ='" & MEAnumber & "';"
'MsgBox strSQL
CurrentDb.Execute strSQL
End If


End Sub
 
D

Douglas J. Steele

Add On Error GoTo Err_MembraneType_AfterUpdate at the very beginning of the
routine, and the following at the very end:

End_MembraneType_AfterUpdate:
Exit Sub

Err_MembraneType_AfterUpdate:
Select Case Err.Number
Case 3022
' put your custom error message here
Case Else
MsgBox Err.Description & " (" & Err.Number & ")"
End Select
Resume End_MembraneType_AfterUpdate
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top