IF statements (1 Viewer)

peterbowles

Registered User.
Local time
Today, 15:04
Joined
Oct 11, 2002
Messages
163
This is the code

If Me.Textbox1 = IDnumber (Value in the table) Then

Me.Text50 = "Hello" & DLookup("Name", "passcode", "IDNumber
= '" & Me.password & "'")

Me.Command6.Visible = True
Me.Command7.Visible = True
Me.Command8.Visible = True
Me.Command9.Visible = True
Me.Command10.Visible = True
Me.Command19.Visible = True

Else: Me.textbox1 = "Invalid Number"

End If

End Sub


The problem is that it only returns a value if the ID number in the textbox is the same as the current record on the form . It does not look through the whole table

Why?

Any help would be great

Thanks
 

peterbowles

Registered User.
Local time
Today, 15:04
Joined
Oct 11, 2002
Messages
163
MikeAngelastro said:
What exactly are you trying to do? [/QUOTE

a user types in an ID number into a textbox on a form (Me.password) I then use a DLookup to find if that password has a name related to it. If yes then the name appears in another field. If no then a message indicating that is is an invalid number is shown.

the code looks like this

If Me.password = IDNumber (Value in table) Then
Me.Text50 ="Hello" & DLookup("Name", "passcode", "IDNumber_ = '" & Me.password & "'")

else

Me.text50 = "Invalid number please try again"

End If

End SUb

The problem is that the function only looks at that first value in the related table. eg. I have 101,102,103,104,105 as IDNumbers. If a user types in one of these numbers only the first value os the table 101 is regonised and the rest are not found

Please help
 

Pat Hartman

Super Moderator
Staff member
Local time
Today, 10:04
Joined
Feb 19, 2002
Messages
43,374
dim PersonName as Variant
PersonName = DLookup("Name", "passcode", "IDNumber_ = '" & Me.password & "'")

If IsNull(PersonName) Then
Me.text50 = "Invalid number please try again"
else
Me.Text50 ="Hello " & PersonName
End If

End SUb


[Name] and [password] are poor choices for column names since they are both reserved words in VBA. ALWAYS surround them with square brackets or be prepared for strange happenings.
 

Users who are viewing this thread

Top Bottom