Multiple Criteria

M

m stroup

I have a form field I want to populate based on the last record of a table
but I would like to use two criteria.

I want to get the EngineHrs from the last record in tblEngineMaintenance
where the SerialNumber matches the EngineTxt field on my form and the Type Is
Spark Plug.

Can you tell me if I am close?

LastSPMaint = DLast("[EngineHrs]", "tblEngineMaintenance", "[SerialNumber] =
EngineTxt.Value" And "[Type] = ' Spark Plug' ")
 
D

Douglas J. Steele

Close, but your quotes are wrong. AND needs to be inside the quotes (and the
reference to the field on your form needs to be outside of the quotes):

LastSPMaint = DLast("[EngineHrs]", "tblEngineMaintenance", _
"[SerialNumber] = " EngineTxt.Value & " And [Type] = 'Spark Plug' ")

This assumes that SerialNumber is a numeric field (which is seldom a good
idea). If it's text, you need to put quotes around the value:

LastSPMaint = DLast("[EngineHrs]", "tblEngineMaintenance", _
"[SerialNumber] = '" EngineTxt.Value & "' And [Type] = 'Spark Plug' ")


(Note, too, that you had a space after the opening quote and the word Spark.
Presumably that's an error.)
 
M

m stroup

Thanks Doug.

It is working fine now.
--
Teach me to fish! Thanks for the help.
Pax, M


Douglas J. Steele said:
Close, but your quotes are wrong. AND needs to be inside the quotes (and the
reference to the field on your form needs to be outside of the quotes):

LastSPMaint = DLast("[EngineHrs]", "tblEngineMaintenance", _
"[SerialNumber] = " EngineTxt.Value & " And [Type] = 'Spark Plug' ")

This assumes that SerialNumber is a numeric field (which is seldom a good
idea). If it's text, you need to put quotes around the value:

LastSPMaint = DLast("[EngineHrs]", "tblEngineMaintenance", _
"[SerialNumber] = '" EngineTxt.Value & "' And [Type] = 'Spark Plug' ")


(Note, too, that you had a space after the opening quote and the word Spark.
Presumably that's an error.)

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


m stroup said:
I have a form field I want to populate based on the last record of a table
but I would like to use two criteria.

I want to get the EngineHrs from the last record in tblEngineMaintenance
where the SerialNumber matches the EngineTxt field on my form and the Type
Is
Spark Plug.

Can you tell me if I am close?

LastSPMaint = DLast("[EngineHrs]", "tblEngineMaintenance", "[SerialNumber]
=
EngineTxt.Value" And "[Type] = ' Spark Plug' ")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top