Comparing entered data to table

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

Guest

I have a table that contains a list of group numbers. On an entry form when
the user enters the group number i'd like to have it compare that group
number to the list on the other table. havin trouble with the vb code. the
table name is GroupTable, field is GroupNbr and the entered field on the form
is strGroupNbr. Thanks
 
What other table? you only reference one table, so I am guessing your want to
see if the value in strGroupNbr is in a field named [GroupNbr] in the table
GroupTable.
If this is correct, then all you need is:

If IsNull(DLookUp("[GroupNbr]", "GroupTable", "[GroupNbr] = '" & _
strGroupNbr & "'")) Then
MsgBox strGroupNbr & " was not found in GroupTable"
Else
do whatever
End If

Now, a point about naming conventions. the str Prefix (strGrouNbr) usually
indicates a string variable. A Text Box Control (not field, fields belong to
tables) is usually prefixed with txt. Not a bitch, just a friendly pointer.
 
sorry...the field strGroupNbr is located in my main table and i'm comparing
that field to the list of group numbers in my GroupTable. does that make a
diff in the code you suggested?

Klatuu said:
What other table? you only reference one table, so I am guessing your want to
see if the value in strGroupNbr is in a field named [GroupNbr] in the table
GroupTable.
If this is correct, then all you need is:

If IsNull(DLookUp("[GroupNbr]", "GroupTable", "[GroupNbr] = '" & _
strGroupNbr & "'")) Then
MsgBox strGroupNbr & " was not found in GroupTable"
Else
do whatever
End If

Now, a point about naming conventions. the str Prefix (strGrouNbr) usually
indicates a string variable. A Text Box Control (not field, fields belong to
tables) is usually prefixed with txt. Not a bitch, just a friendly pointer.

brad said:
I have a table that contains a list of group numbers. On an entry form when
the user enters the group number i'd like to have it compare that group
number to the list on the other table. havin trouble with the vb code. the
table name is GroupTable, field is GroupNbr and the entered field on the form
is strGroupNbr. Thanks
 
No, I thought that is what you meant. It should work for you as is.

brad said:
sorry...the field strGroupNbr is located in my main table and i'm comparing
that field to the list of group numbers in my GroupTable. does that make a
diff in the code you suggested?

Klatuu said:
What other table? you only reference one table, so I am guessing your want to
see if the value in strGroupNbr is in a field named [GroupNbr] in the table
GroupTable.
If this is correct, then all you need is:

If IsNull(DLookUp("[GroupNbr]", "GroupTable", "[GroupNbr] = '" & _
strGroupNbr & "'")) Then
MsgBox strGroupNbr & " was not found in GroupTable"
Else
do whatever
End If

Now, a point about naming conventions. the str Prefix (strGrouNbr) usually
indicates a string variable. A Text Box Control (not field, fields belong to
tables) is usually prefixed with txt. Not a bitch, just a friendly pointer.

brad said:
I have a table that contains a list of group numbers. On an entry form when
the user enters the group number i'd like to have it compare that group
number to the list on the other table. havin trouble with the vb code. the
table name is GroupTable, field is GroupNbr and the entered field on the form
is strGroupNbr. Thanks
 
thank you very much for you help.

Klatuu said:
No, I thought that is what you meant. It should work for you as is.

brad said:
sorry...the field strGroupNbr is located in my main table and i'm comparing
that field to the list of group numbers in my GroupTable. does that make a
diff in the code you suggested?

Klatuu said:
What other table? you only reference one table, so I am guessing your want to
see if the value in strGroupNbr is in a field named [GroupNbr] in the table
GroupTable.
If this is correct, then all you need is:

If IsNull(DLookUp("[GroupNbr]", "GroupTable", "[GroupNbr] = '" & _
strGroupNbr & "'")) Then
MsgBox strGroupNbr & " was not found in GroupTable"
Else
do whatever
End If

Now, a point about naming conventions. the str Prefix (strGrouNbr) usually
indicates a string variable. A Text Box Control (not field, fields belong to
tables) is usually prefixed with txt. Not a bitch, just a friendly pointer.

:

I have a table that contains a list of group numbers. On an entry form when
the user enters the group number i'd like to have it compare that group
number to the list on the other table. havin trouble with the vb code. the
table name is GroupTable, field is GroupNbr and the entered field on the form
is strGroupNbr. Thanks
 
Back
Top