Text Box Validation

G

Guest

How do I have a text box validate the number entered against values in a
seperate table?

I have created a keypad on a form for users to enter an ID number with a
touch sreen. I had to remove the combo box because users were having a hard
time using the touch sreen to select their ID from a list. Also, people were
complaining about the drop down arrow appearing on the right side of the box.

All I'm trying to do is for a user to enter an ID number in a text box and
if they enter an invalid ID number I would like to display an error message
indicating that they did so.
 
R

ruralguy via AccessMonster.com

Use a DLookup() or DCount() function in the BeforeUpdate event of the TextBox
and set Cancel = True to hold the focus in the control.
 
G

Guest

Thank you for responding. I attempted to use dlookup() in the BeforeUpdate
event of the text box but received the following error: Compile Error:
Expected =

Here is the code I have. dlookup("[LastName]","[tblMembers]","[MemberID]= "
& "[txtSignIn]")

I'm assuming this will return the Last Name of a member. I really don't
want this, all I want to do is to check that the member ID is valid before
opening a different form. If the Member ID is invalid, I would like to
display a message alerting them that they entered an invalid ID.

MemberID is a numeric field.
 
R

ruralguy via AccessMonster.com

Both DCount() and DLookup() return values and you need to use them or you
will get the compile error you received.

If IsNull(dlookup("[LastName]","[tblMembers]","[MemberID]= " & Me.txtSignIn)
Then
Cancel = True
MsgBox "Invalid Member ID"
End If

Thank you for responding. I attempted to use dlookup() in the BeforeUpdate
event of the text box but received the following error: Compile Error:
Expected =

Here is the code I have. dlookup("[LastName]","[tblMembers]","[MemberID]= "
& "[txtSignIn]")

I'm assuming this will return the Last Name of a member. I really don't
want this, all I want to do is to check that the member ID is valid before
opening a different form. If the Member ID is invalid, I would like to
display a message alerting them that they entered an invalid ID.

MemberID is a numeric field.
Use a DLookup() or DCount() function in the BeforeUpdate event of the TextBox
and set Cancel = True to hold the focus in the control.
[quoted text clipped - 10 lines]
 
G

Guest

RG - Thank you for the reply. Your code worked great! If I tab out of the
box I receive the error message. If I click a command button then it isn't
validating the member ID. I will look at the code on the command button to
see if I need to add similar code to it.

This form only have 1 text box for members to enter their ID and 2 command
buttons. 1 to cancel their entry and an OK button which allows them to
proceed to another form.

Thanks again RG.


Private Sub txtSignIn_BeforeUpdate(Cancel As Integer)

If IsNull(DLookup("[LastName]", "[tblMembers]", "[MemberID]= " &
Me.txtSignIn)) Then
Cancel = True
MsgBox "Invalid Member ID"
End If

End Sub




ruralguy via AccessMonster.com said:
Both DCount() and DLookup() return values and you need to use them or you
will get the compile error you received.

If IsNull(dlookup("[LastName]","[tblMembers]","[MemberID]= " & Me.txtSignIn)
Then
Cancel = True
MsgBox "Invalid Member ID"
End If

Thank you for responding. I attempted to use dlookup() in the BeforeUpdate
event of the text box but received the following error: Compile Error:
Expected =

Here is the code I have. dlookup("[LastName]","[tblMembers]","[MemberID]= "
& "[txtSignIn]")

I'm assuming this will return the Last Name of a member. I really don't
want this, all I want to do is to check that the member ID is valid before
opening a different form. If the Member ID is invalid, I would like to
display a message alerting them that they entered an invalid ID.

MemberID is a numeric field.
Use a DLookup() or DCount() function in the BeforeUpdate event of the TextBox
and set Cancel = True to hold the focus in the control.
[quoted text clipped - 10 lines]
if they enter an invalid ID number I would like to display an error message
indicating that they did so.

--
RuralGuy (RG for short) aka Allan Bunch MS Access MVP - acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via AccessMonster.com
 
G

Guest

RG - It works with the command button also. Thank you again so very much for
all of your help. I appreciate it very much.



ruralguy via AccessMonster.com said:
Both DCount() and DLookup() return values and you need to use them or you
will get the compile error you received.

If IsNull(dlookup("[LastName]","[tblMembers]","[MemberID]= " & Me.txtSignIn)
Then
Cancel = True
MsgBox "Invalid Member ID"
End If

Thank you for responding. I attempted to use dlookup() in the BeforeUpdate
event of the text box but received the following error: Compile Error:
Expected =

Here is the code I have. dlookup("[LastName]","[tblMembers]","[MemberID]= "
& "[txtSignIn]")

I'm assuming this will return the Last Name of a member. I really don't
want this, all I want to do is to check that the member ID is valid before
opening a different form. If the Member ID is invalid, I would like to
display a message alerting them that they entered an invalid ID.

MemberID is a numeric field.
Use a DLookup() or DCount() function in the BeforeUpdate event of the TextBox
and set Cancel = True to hold the focus in the control.
[quoted text clipped - 10 lines]
if they enter an invalid ID number I would like to display an error message
indicating that they did so.

--
RuralGuy (RG for short) aka Allan Bunch MS Access MVP - acXP WinXP Pro
Please post back to this forum so all may benefit.

Message posted via AccessMonster.com
 
R

ruralguy via AccessMonster.com

Glad I could help. Thanks for posting back with your success.
RG - It works with the command button also. Thank you again so very much for
all of your help. I appreciate it very much.
Both DCount() and DLookup() return values and you need to use them or you
will get the compile error you received.
[quoted text clipped - 24 lines]
 

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