Message Box Assisstance

G

Guest

Hi,

I have a field DriverNo in a table called tblStaff.

I have made the property Indexed to be Yes (No Duplicates).

I would like a message to pop up if a user tries to enter a duplicate
DriverNo.

I've never used Message Boxes before.

Thanks

Greg.
 
K

Keith Wilby

Greg said:
Hi,

I have a field DriverNo in a table called tblStaff.

I have made the property Indexed to be Yes (No Duplicates).

I would like a message to pop up if a user tries to enter a duplicate
DriverNo.

I've never used Message Boxes before.

You will get a run-time error message for free if a duplicate entry is
attempted.

Regards,
Keith.
www.keithwilby.com
 
J

John Spencer

Where (from a form, from a datasheet) and When (upon entry of the data for
Driver No, when the record is saved)?

Assumption:
Entry on a form into a control.

When exiting the control after updating it, you want a message warning the
user that this is a duplicate and cannot be saved.

Private Sub txtDriverNoControlName _AfterUpdate()
IF DCount("*","TblStaff","[Driver no]=" & Chr(34) &
me.txtDriverNoControlName & Chr(34)) > 0 Then
MsgBox "This Driver Number is a duplicate. You may not be able to save
this record",,"Suspected Duplicate"
END IF
End Sub


If Driver No is a number field and not a text field then remove the Chr(34)
from the DCount.
 

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

Similar Threads


Top