Is it possible to change the wording of a system mssg.
i.e. If duplicate record entered in a Primary key field can the mssg be setup simply as 'duplicate record entered' INSTEAD of the long system mssg which isn't that clear.
It is possible to turn off System Messages, even if it's only temporary, and create your own message.
I.e.
In the event that causes the system message to occur, use this code.
DoCmd.SetWarnings = False
If MsgBox("Duplicate record entered.", 65, "Warning" = vbOk Then 'Do whatever you want in here
Else 'Do something else in here
End if
Docmd.setwarnings = True
Yes it would go in the AfterUpdate event of the primary key control but you would have to perform a check first to see whether the user was entering a duplicate record.
If they were then you could use the above code.
The Do whatever you want/do something else means what to do depending on what button the user presses.
The 65 in the MsgBox line of code tells Access what kind of Msgbox to display.
The VbOKCancel msgbox = 1
A VbInformation msgbox = 64
so add these together and you get an Ok/Cancel message box styled as an information box. Check out Access help for all the values or you can just type VbOkCancel+VbInformation instead of 65.
If the user pressed cancel you could stop the primary control losing focus so they could change what they entered, you'd do this by entering some code in the Else part of the above code where it says 'Do something else
If they pressed Ok you could just do nothing and let them carry on, so don't put any code in the part that says 'Do whatever you want.
Here's a better example:
DoCmd.SetWarnings = False
If MsgBox("Duplicate record entered.", 65, "Warning" = vbCancel Then
[YourControl].SetFocus
End if
If you enter that into the AfterUpdate event and then have
Docmd.setwarnings = True
on the On Got Focus event of your control, you should be away.
Thanks for the reply Pete. This prob is on access 2000.
I'm Having probs with the 'dlookup' function. I've put this in:-
If DLookup("[SocSecID]", "[Client]", "[SocSecID] =" & Me!SocSecID) Then
MsgBox "duplicate, try again"
DoCmd.GoToControl "SocSecID"
End If
Table name- Client
Field on Table name- SocSecID
Form field name- SocSecID
I get a 'run time error 3464. Data mismatch in criteria'
The SocSecID field is a text field with input mask of 000-00-000.
Try not encasing the table name, ie Client, in square brackets. Also I may be wrong but DLookup returns a Null or a field value so you'll have to check that it's not null to be sure that there is a duplicate record. So try the code this way:
If Not (DLookup("[SocSecID]", "Client", "[SocSecID] = " & Me!SocSecID) = vbNull) Then
MsgBox "duplicate, try again"
DoCmd.GoToControl "SocSecID"
End If
If DLookup("[SocSecID]", "[Client]", "[SocSecID] =" & Me!SocSecID) Then
MsgBox "duplicate, try again"
DoCmd.GoToControl "SocSecID"
End If
The problem was the 'data type'on the 'SocsecID' field. It was set to 'text'. Changed it to 'number' and it worked!!
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.