Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change system error message 2

Status
Not open for further replies.

lpgagirl

Technical User
Feb 3, 2003
202
CA
I have created an index that prevents duplicate entries on two fields (same first and last name). Access generates an auto message when a duplicate occurs so that it can't be saved. Can I change the content of the message...or how can I have my own error message pop-up, not the system message.

Thanks in advance,



Jeannie
 
How are you saving data to the table? Is it a bound or unbound form?

Ed Metcalfe.

Please do not feed the trolls.....
 
The form is bound to a Query (derived from Main table). The new record is saved using a button control. When the button is clicked to save, I have a dialogue box which appears to ask the user "Do you want to save this record?"

Hope this helps,



Jeannie
 
Private Sub Command4_Click()
On Error GoTo Err_Command4_Click

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord, , acMenuVer70

Exit_Command4_Click:
Exit Sub

Err_Command4_Click:
If Err.Number = 2046 Or Err.Number = 3022 Then
MsgBox "The record you are trying to save already exists within the system. Data cannot be saved at this time.", vbExclamation, "Duplicate Data!"
Resume Exit_Command4_Click
Else
MsgBox Err.Description
Resume Exit_Command4_Click
End If

Ed Metcalfe.

Please do not feed the trolls.....
 
If you do not wish to use a button, it is possible to use Form_Error, for example, the code below will produce a custom message in place of the Access message in every (?) case:
Code:
Private Sub Form_Error(DataErr As Integer, Response As Integer)
      Const DUPLICATE_VALUES = 3022
      If DataErr = DUPLICATE_VALUES Then
         MsgBox "Tut, Tut"
         Response = acDataErrContinue
      End If
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top