Check for duplicate upon lost focus

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have an input for named "Inputting". It checks to make sure the number
entered is not in the tblDNUMBER when moving to the next record because
tblDNUMBER.Number propertry is unique. I would like to confirm the input
number is unique after the field has lost focus (I already have an event "On
Exit"). After someone has entered the number and the code for on exit has
ran haow can I have the form check the tblDNUMBER to confirm that number is
not in that table and display an error msg if the number is found in
tblDNUMBER?
 
Rod

It sounds like you are forcing your users to input a number. Even if they
happen to know the right number, they still could, like me, have fat clumsy
fingers that make misteaks.

Would it be more user-friendly for them to have a combobox to select the
correct number from?

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
Wouldn't it be less intrusive to use the control's BeforeUpdate event?
It can be cancelled; if you use the Exit event, the record has already
been written to the table, and it's too late.

John W. Vinson[MVP]
 
Hi John,

I like your suggestion. I'll use it.

How would I check for uniqueness? (Part of the problem here is I am a self
taught Access user.)
 
Hi John,

I like your suggestion. I'll use it.

How would I check for uniqueness? (Part of the problem here is I am a self
taught Access user.)

Since I don't know anything about your table structure I can't say
specifically, but you'ld use DLookUp() to search the table for an
existing value for the current field:

Private Sub Form_BeforeUpdate(Cancel as Integer)
If Not IsNull(DLookUp("[Phone]", "[tablename]", _
"[Phone] = '" & Me!txtPhone & "'") Then
MsgBox "This phone number already exists", vbOKOnly
Cancel = True
<do whatever else is appropriate, e.g. move to the found record>
End If
End Sub

John W. Vinson[MVP]
 
Back
Top