Multiple Criteria

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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' ")
 
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.)
 
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' ")
 
Back
Top