I'm trying to set up error handling in an Access app that connects to a SQL Server backend to prevent Access passing a null primary key to the server.
I'm using BeforeUpdate and code based on Properly Handling Errors in VBA (Excel)
My code is supposed to run the ErrHandler code if the user sets S_ID to null (or leaves it as null when creating a new record). But instead it's always running the ErrHandler code.
Private Sub S_ID_BeforeUpdate(Cancel As Integer)
Dim trigger As Integer
On Error GoTo ErrHandler
If Me.S_ID Is Null Then
trigger = 1 / 0
End If
Exit Sub
ErrHandler:
MsgBox ("Key was null, fix it")
Resume Resume_spot
Resume_spot:
End Sub
I've yet to write the code for what I want Access to do when the error occurs, hence the useless MsgBox
and lack of anything after Resume_spot
. Before I get that far I want to get the error handling to trigger properly.