Open new form based on 2 fields.

L

Lurch

Hi There!

I have a small problem. I have a form with a button that when I click it'll
open another form with just that record. I'm using the
strLinkCriteria....What is the proper syntax for doing the same thing but
with two fields being equal...

Eg.
Location on form1 opens a only that record with the same location in form2.
How can I have Location and ZIP on form1 open the record in Form2 that
matches both Location and ZIP in form2...

I hope that made sense!! haha

Thanks everyone!

Lurch
 
A

Allen Browne

The strLinkCriteria has to end up looking like the WHERE clause of a query.
You can mock up a query using some literal values in the Criteria row, and
then switch to SQL View (View menu in query design) to see what the WHERE
clause looks like.

Text fields need quote marks around the literal value, and date fields need
to be delimited with #. Numeric fields do not have a delimiter, so you need
to use Nz() to supply some value; otherwise the resultant string will not
work if the field is null. (It is possible to use BuildCriteria to get these
if you desire.)

This example shows the kind of thing you need, showing a number field and a
text field:

strLinkCritiera = "([SomeNumberField] = " & Nz(Me.[SomeNumberField],0) & ")
AND ([SomeTextField] = """ & Me.[SomeTextField] & """)"
DoCmd.OpenForm "Form2", WhereCondition:=strLinkCriteria
 

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