robertsfd
Technical User
- Apr 18, 2003
- 40
I have a form with a listbox control lstVIN which is populated with records from a table of vehicles (bound on the field VIN). Based on what vehicle the user selects, I want a variable to hold the result of the following query (which will be a single number):
SELECT Max(EndingMileage) FROM GasFill WHERE VIN=Forms!GasFill!lstVIN
What I thought was - but after searching the archives I think I may be in over my beginner VBA head - it would be something like this:
Dim strSQL as String
Dim intEndMileage as Integer
strSQL = "SELECT Max(EndingMileage) FROM GasFill WHERE VIN=Forms!GasFill!lstVIN"
EndMileage = DoCmd.RunSQL(strSQL)
This doesn't work of course. However, I don't know where to go now. Any help would be greatly appreciated. I had supposed that something like this could be done without knowing much (as I don't) but I was wrong. Perhaps I am close.
Thanks in advance for any help.
SELECT Max(EndingMileage) FROM GasFill WHERE VIN=Forms!GasFill!lstVIN
What I thought was - but after searching the archives I think I may be in over my beginner VBA head - it would be something like this:
Dim strSQL as String
Dim intEndMileage as Integer
strSQL = "SELECT Max(EndingMileage) FROM GasFill WHERE VIN=Forms!GasFill!lstVIN"
EndMileage = DoCmd.RunSQL(strSQL)
This doesn't work of course. However, I don't know where to go now. Any help would be greatly appreciated. I had supposed that something like this could be done without knowing much (as I don't) but I was wrong. Perhaps I am close.
Thanks in advance for any help.