Detecting text entered in a text field

S

Shaldaman

Is there a method or property to check if text has been entered in a
text field on a form? The way I have my form set up is if a user enters
data in the text field and closes the form, the data gets stored in the
table. Problem is, if the user enters existing data and closes the
form, they are not prompted that the value already exists in the table.
However, there's no redundant data in the table - when an existing
value is entered and the form's closed, nothing's happening. I want to
be able to prompt the user on typing text in the field and tabbing over
to the next field, i.e. the moment he/she moves to another field or
control on the form, they should get a warning. I can't use DCount or
DLookup because i'm using a continuous form - existing values fill up
that text field which appear one below the other. The bottom most field
is blank for data entry.
 
D

Dirk Goldgar

Shaldaman said:
Is there a method or property to check if text has been entered in a
text field on a form? The way I have my form set up is if a user
enters data in the text field and closes the form, the data gets
stored in the table. Problem is, if the user enters existing data and
closes the form, they are not prompted that the value already exists
in the table. However, there's no redundant data in the table - when
an existing value is entered and the form's closed, nothing's
happening. I want to be able to prompt the user on typing text in the
field and tabbing over to the next field, i.e. the moment he/she
moves to another field or control on the form, they should get a
warning. I can't use DCount or DLookup because i'm using a continuous
form - existing values fill up that text field which appear one below
the other. The bottom most field is blank for data entry.

The text box's BeforeUpdate and AfterUpdate events will fire when the
user enters anything in it and moves the focus off the control. You
should be able to use one of those events to check if this value already
exists in the table. I'm not sure why you say, "I can't use DCount or
DLookup because i'm using a continuous form." I'd expect something like
this to work:

'---- start of example code ----
Private Sub YourField_BeforeUpdate(Cancel As Integer)

If Not IsNull(YourField) Then

If Not IsNull(DLookup("YourField", "YourTable", _
"YourField=" & Chr(34) & Me!YourField & Chr(34))) _
Then
MsgBox "This value is already in the table. Try another
value."
Cancel = True
End If

End If

End Sub
'---- end of example code ----
 

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