Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

DLookup with criteria 1

Status
Not open for further replies.

JaineyBlue

Technical User
Sep 27, 2023
8
CA
I inherited a vehicle tracking dB and trying to make some updates. Have a 'Tbl-Types' which lists vehicle, equipment and trailer types, as well as chassis types (Field1 combobox has 'A','V','E','T' choices). I want the vehicle form to autofill a fleet plan code (VWOCode) for each unit. Form currently has two fields VehicleCode and Chassis_Type which pull from the same field 'ComponentType' in Tbl-Types. There is no fleet plan code for chassis types because if a vehicle is a utility truck on a pickup truck body it needs to be included in a utility truck fleet plan, not pickup trucks. Current code is
VWOCode = DLookup("VWOCode","Tbl-Types","ComponentType='" & VehicleCode & "'")
Works wherever the vehicle type is different than the chassis type but if they are the same (eg a pickup truck that is just a pickup truck) it is pulling the empty VWOCode in the chassis record. How can I restrict the results to Types V,E,T only?
 
DLookup works pretty much as:

DLoolup(“Give me a value from this field”, “table or query where this fields is”, “criteria to get the value – Where statement”)

So, if you have those Types V,E,T in Tbl-Types table, you can [blue]add to your criteria[/blue]:
Code:
VWOCode = DLookup("VWOCode","Tbl-Types","ComponentType='" & VehicleCode & "' [blue]And Types IN ('V','R','T')[/blue]")

---- Andy

"Hmm...they have the internet on computers now"--Homer Simpson
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top