Criteria Expression

T

Toco Hara

I have problem with concatinating my string expression.
There are 3 fields that I try to include in my
expression: CustomerNumber, DtOrder, DtReviewed. I try
to send the values from the first form to the second form,
but 2 of them are dates and my string expression is not
right. Can anyone correct my syntax? Am I openening the
second form not correctly? Here is OnClick Method of
button on the first form:

strDocName = "frmOrder"
strLinkCriteria = "[DtOrder]=" & "#" & Me![DtOrder] & "#"
& " AND [CustomerNumber] = '" & Me![CustomerNumber] & "
AND [DtReviewed]= " & "#" & Me![DtReviewed] & "#" & "'"

DoCmd.OpenForm strDocName, , , strLinkCriteria
'Forms!frmOrder![SaveID] = Me![CustomerNumber]
'Forms!frmOrder![SaveDt] = Me![DtOrder]
'Forms!frmPCR![SaveReviewed] = Me![DtReviewed]
 
T

Toco Hara

Thank you Joshua. Your message gave me what is needed.

Toco
-----Original Message-----
Toco,

Criteria expressions can be tricky especially with data types other than
number. It looks like you understand that you need to surround dates with #
and text with quotes. I see an extra quote at the end of the criteria.
Perhaps you added the DtReviewed later and left the CustNumber quote at the
end by mistake. I have found it easier to use the chr (34) instead of nested
quotes because it's easier to read and to debug. Try this:

strDocName = "frmOrder"
strLinkCriteria = "[DtOrder]= " & "#" & Me![DtOrder] & "#"
& " AND [CustomerNumber] = " & chr(34) & Me! [CustomerNumber] & Chr(34) & "
AND [DtReviewed] = " & "#" & Me![DtReviewed] & "#"

DoCmd.OpenForm strDocName, , , strLinkCriteria

Hint: You can through in this code:

Debug.Print stLinkCriteria

which will print the resulting string in the immediate window. That way you
will see the extra or missing quotes and such.

HTH,
Josh


Toco Hara said:
I have problem with concatinating my string expression.
There are 3 fields that I try to include in my
expression: CustomerNumber, DtOrder, DtReviewed. I try
to send the values from the first form to the second form,
but 2 of them are dates and my string expression is not
right. Can anyone correct my syntax? Am I openening the
second form not correctly? Here is OnClick Method of
button on the first form:

strDocName = "frmOrder"
strLinkCriteria = "[DtOrder]=" & "#" & Me![DtOrder] & "#"
& " AND [CustomerNumber] = '" & Me![CustomerNumber] & "
AND [DtReviewed]= " & "#" & Me![DtReviewed] & "#" & "'"

DoCmd.OpenForm strDocName, , , strLinkCriteria
'Forms!frmOrder![SaveID] = Me![CustomerNumber]
'Forms!frmOrder![SaveDt] = Me![DtOrder]
'Forms!frmPCR![SaveReviewed] = Me![DtReviewed]


.
 

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