Dlookup Problem

  • Thread starter Thread starter David W
  • Start date Start date
D

David W

I am trying to find out if a value exist from a different table and if it
does warn the user.

I have a combobox that gets its value list from a query that orginates from
another combobox's selection(group values).
All of this works fine.
What I am trying to do is to keep someone from entering a value that already
exist but belongs to another group.

I tried this but it always returned a null requardless if it was or wasnt in
the list.

If Not IsNull(DLookup("vehicle", "vehiclelist", "vehicle = '" & NewData &
"'")) Then
'do something
Else
'or do this
end if

vehicle is the fieldlist
vehiclelist is the table
NewData is what is selected from the combobox
The field is of a text value.

I am using the NotInList event of the combo and it works fine, but what I
dont want is the user typing in a value that belongs to another group.
How can this be done....
 
David, try this...

If Not IsNull(DLookup("[vehicle]", "vehiclelist", "[vehicle] = '" & NewData
&_
"'")) Then


Cheers
 
That worked
Now lets take it a step further!
How would you get a fields value related to the lookup value
Example

if you use dlookup to find T040 from the vehicle field, how would you return
a number from a field called ID using
If Not IsNull(DLookup("[vehicle]", "vehiclelist", "[vehicle] = '" & NewData
&_
"'")) Then
 
Maybe this will help you...

DLookup("[GetThisFieldInfo]","fromThisTableName","[WhereThisIsEqualTo] ='" &
NewData & "'"))

So, assuming the only difference is the field name you want to look up, your
code would be:

If Not IsNull(DLookup("[Id]", "vehiclelist", "[vehicle] = '" & NewData
& "'")) Then


Cheers
 
Back
Top