5 replies
by donq
There are many ways to do what you want. This code is pasted to a Primary Key field's After Update event to automate some of my application functions, and it traps the normal Access error when a duplicate key value insertion is attempted. I have modified the line you need to change for clarity. Good Luck!
Private Sub omfPK_AfterUpdate()
On Error GoTo Err_omfPK_AfterUpdate
'AUTOMATICALLY SET THE omtLuid FIELD TO THE CURRENT USER AND
'SET THE AUTOMATED UPDATE VALUE TO THE CURRENT CLOCKTIME
'EVERY TIME THIS FIELD VALUE IS CHANGED.
omfLuid = CurrentUser()
omfUpd = Now()
Exit_omfPK_AfterUpdate:
Exit Sub
Err_omfPK_AfterUpdate:
MsgBox "Enter whatever text you want displayed in quotes here"
Resume Exit_omfPK_AfterUpdate
End Sub
by cooger
by whyong
try to put this code in your form's on error event...
Private Sub Form_Error(DataErr As Integer, Response As Integer)
Const conDuplicateKey = 3022
Dim strMsg As String
If DataErr = conDuplicateKey Then
Response = acDataErrContinue
strMsg = "Each employee record must have a unique " _
& "employee ID number. Please recheck your data."
MsgBox strMsg
End If
End Sub
happy coding
by cooger
by cooger
This discussion is closed to new replies.
Trending Web Development posts
Sort by Trending