How to prevent field from duplicated data if check box is true?

J

Jon

I have 3 fields, employee ID, Name, employee Pass (Yes/No) and Grade. What I
want to do is if the employee Pass Field is checked and we try to register
this employee again, a massage box appears and shows the status and undo the
event. How to do that?
 
T

Tom van Stiphout

On Wed, 3 Dec 2008 03:40:25 -0800, Jon <[email protected]>
wrote:

"Try to register": that sounds like the Form_BeforeUpdate event. In
it, you could write:
(of course I guessed at your object names)
if Me.Pass = True then
if dcount("EmployeeID", "tblEmployees", "EmployeeID=" &
Me.EmployeeID) > 0 then
Msgbox "Aarrrccchhhhh, you are attempting to enter a duplicate!",
vbCritical
Cancel = True
end if
end if

Note the "Cancel=True" line: it cancels the event so the record cannot
be saved.

-Tom.
Microsoft Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top