MikeMcKeown
Programmer
Hi,
I am trying to catch errors for null primary key or duplicate keys. I have put the following code into the forms OnError event. I am using an adp project with a SQL Server database. I think I am catching two error the SQL Server one and Access one and only displaying one message.
If (DataErr = 2627 Or DataErr = 2169) Then
Response = acDataErrContinue
End If
If (DataErr = 515) Then
If MsgBox("Are you sure you want to exit and not save the current record?", vbOKCancel) = vbOK Then
Cancel = False
Response = acDataErrContinue ' telling Access not to show default message
Else
Cancel = True
Response = acDataErrContinue ' telling Access not to show default message
Me.Form.Undo
End If
End If
This code successfully only displays the message box once and if the user selects ok, the form closes and does not save anything. Else if the user selects cancel, I want them to be able to return to the form and correct their mistakes. However the form just closes as well.
Any ideas
I am trying to catch errors for null primary key or duplicate keys. I have put the following code into the forms OnError event. I am using an adp project with a SQL Server database. I think I am catching two error the SQL Server one and Access one and only displaying one message.
If (DataErr = 2627 Or DataErr = 2169) Then
Response = acDataErrContinue
End If
If (DataErr = 515) Then
If MsgBox("Are you sure you want to exit and not save the current record?", vbOKCancel) = vbOK Then
Cancel = False
Response = acDataErrContinue ' telling Access not to show default message
Else
Cancel = True
Response = acDataErrContinue ' telling Access not to show default message
Me.Form.Undo
End If
End If
This code successfully only displays the message box once and if the user selects ok, the form closes and does not save anything. Else if the user selects cancel, I want them to be able to return to the form and correct their mistakes. However the form just closes as well.
Any ideas