DLookup Syntax Error with 1 text and 1 numerical field

riverwatch

New member
Local time
Today, 05:38
Joined
Jan 11, 2016
Messages
5
Hello, I have a query designed to calculate gas mileage for multiple vehicles. I am working on a DLookup statement in a query to return the previous mileage value for the same vehicle in order to calculate fuel efficiency.

The following statement works to return the previous mileage value using the previous service ID (numerical):

PreviousMileage: DLookUp("[Mileage]","VehicleGasMileageQ","[ServiceID]=" & [ServiceID]-1)

However, I have multiple vehicles in the database and therefore need to add a criteria statement for the text field [VehicleID] = [Vehicle ID]. How would I add that piece to my DLookup statement?

Thank you
 
DLookUp("[Mileage]","VehicleGasMileageQ","[ServiceID]=" & [ServiceID]-1 & " and [VehicleID] = " & txtVehID)
 
Thanks Ranman256,

I'm still working out the concatentation rules. VehicleID is a text variable in the DLookup based on another field in the query. So I incorporated your suggestion to make:

PreviousMileage: DLookUp("[Mileage]","VehicleGasMileageQ","[ServiceID]=" & [ServiceID]-1 & " and [VehicleID] = " & [VehicleID])

However, when I run the query, it gives errors for the previous mileage field. When I click on the error it says: Syntax error (missing operator) in query expression ‘[ServiceID]=67 and [VehicleID] = 2008 Dodge Caravan’

I'm guessing there is some missing quotation marks for VehicleID in the DLookup? Sorry, I'm pretty new at SQL :eek:
 

Users who are viewing this thread

Back
Top Bottom