J
jaman57
I have a form where the field "tpdr" is the primary key of the "data" table,
and is a text field. In order to prevent someone entering a duplicate value
without getting the default Access error message (which would just confuse
them, especially as it would not come until they had finished entering the
other fields farther on in the form when they tried to go to the next
record), I added the following to the "after update" property of the field:
If DLookup("[tpdr]", "data", "[tpdr]=Forms!Input1!tpdr") Then
[tpdr] = ""
MsgBox "This name has already been used, and cannot be duplicated.
Please choose another name."
DoCmd.CancelEvent
DoCmd.GoToControl "tpdr"
End If
This works fine if the attempted duplicate entry in "tpdr" is a number - it
gives the message and retuens the user to the "tpdr" field. But if the
attempted duplicate entry is text, then I get a "Run-time error13. Type
Mismatch." Again the field is a text field, so I don't understand why I am
getting this error. Since the field is a text field it should be treating the
number entry as text, and since it is a text field how can a text entry cause
a type mismatch?
Any ideas?
By the way, this does not work at all if the code is attached to the "Before
Update" property - then it errors out saying that saying the code is
preventing the entry from being saved.
Thanks,
Jeff
and is a text field. In order to prevent someone entering a duplicate value
without getting the default Access error message (which would just confuse
them, especially as it would not come until they had finished entering the
other fields farther on in the form when they tried to go to the next
record), I added the following to the "after update" property of the field:
If DLookup("[tpdr]", "data", "[tpdr]=Forms!Input1!tpdr") Then
[tpdr] = ""
MsgBox "This name has already been used, and cannot be duplicated.
Please choose another name."
DoCmd.CancelEvent
DoCmd.GoToControl "tpdr"
End If
This works fine if the attempted duplicate entry in "tpdr" is a number - it
gives the message and retuens the user to the "tpdr" field. But if the
attempted duplicate entry is text, then I get a "Run-time error13. Type
Mismatch." Again the field is a text field, so I don't understand why I am
getting this error. Since the field is a text field it should be treating the
number entry as text, and since it is a text field how can a text entry cause
a type mismatch?
Any ideas?
By the way, this does not work at all if the code is attached to the "Before
Update" property - then it errors out saying that saying the code is
preventing the entry from being saved.
Thanks,
Jeff