PK duplicate Value

mohammadagul

PrinceAtif
Local time
Today, 19:59
Joined
Mar 14, 2004
Messages
298
how can i customise access messages forexample when a user enteres a dublicate value in product id with pk it gives me an error message as

duplicate value

how can i customise error message. inshort if the value is already in the pk and i enter it again it should look up that value and then give me message like this

"The value you entereed is already in Database. Please enter Unique value"
 
m,

You can use the DLookUp function (on the form's BeforeInsert) event to
display a message box. Use search here for examples of DLookUp.

Wayne
 
Use this Code Before Update Event of the Form

this is the code for the Northwind database for orders form use for your purpose.
If DataErr > 0 Then
If IsNull(Me.Parent!CustomerID) Then
MsgBox "Select a Customer to bill to before entering order details info."
RunCommand acCmdUndo
Me.Parent!CustomerID.SetFocus
Response = acDataErrContinue
ElseIf DataErr = 3022 Then
MsgBox ("Whatever message you want")
SendKeys "{ESC}"
SendKeys "{ESC}"
Else
Response = acDataErrDisplay
End If
End If

End Sub
 
Use the code on error Event

Use the Above code on error event.
 
Simple Code for one form

Private Sub Form_Error(DataErr As Integer, Response As Integer)
If DataErr = 3022 Then
MsgBox ("Whatever message you want")
DoCmd.RunCommand acCmdUndo
SendKeys "{ESC}"
SendKeys "{ESC}"
End If


End Sub
 
Very few would use SendKeys, replace it with Me.Undo instead

If DataErr = 3022 Then
Response = acDataErrContinue
MsgBox ("Whatever message you want")
Me.Undo
End If
 

Users who are viewing this thread

Back
Top Bottom