Open a Form Based on 2 Criteria?

R

Rita

Is it possible to open a form based on 2 criteria? Access 2003 automatically
walks you through design mode for opening a form, but it just allows you to
select one criteria. This is my event procedure.

stDocName = "f Timesheet (Individual Client)"

stLinkCriteria = "[ClientID]=" & Me![ClientID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

I would like it to also match up pay periods. I just copied and pasted this,
but it didn't work. I'm not a programmer--I just cut and paste code:(

stDocName = "f Timesheet (Individual Client)"

stLinkCriteria = "[ClientID]=" & Me![ClientID]
stLinkCriteria = "[PayPeriodDate]=" & Me![PayPeriodDate]
DoCmd.OpenForm stDocName, , , stLinkCriteria

THANKS!!!!
 
A

Allen Browne

Combine the criteria, with AND between them.
Brackets are optional.
If PayPeriodDate is a date, you need to delimit it with #.

Try something along these lines:

If IsNull(Me.ClientID) OR IsNull(Me.PayPeriodDate) Then
MsgBox "Enter both criteria."
Else
stDocName = "f Timesheet (Individual Client)"
stLinkCriteria = "(ClientID = " & Me.ClientID & _
") AND (PayPeriodDate = " & _
Format(Me.PayPeriodDate, "\#mm\/dd\/yyyy\#") & ")"
DoCmd.OpenForm stDocName, WhereCondition:=stLinkCriteria
End If
 
R

Rita

Thanks soooo much! I couldn't believe how quickly you responded! It worked
our perfect!

Allen Browne said:
Combine the criteria, with AND between them.
Brackets are optional.
If PayPeriodDate is a date, you need to delimit it with #.

Try something along these lines:

If IsNull(Me.ClientID) OR IsNull(Me.PayPeriodDate) Then
MsgBox "Enter both criteria."
Else
stDocName = "f Timesheet (Individual Client)"
stLinkCriteria = "(ClientID = " & Me.ClientID & _
") AND (PayPeriodDate = " & _
Format(Me.PayPeriodDate, "\#mm\/dd\/yyyy\#") & ")"
DoCmd.OpenForm stDocName, WhereCondition:=stLinkCriteria
End If

--
Allen Browne - Microsoft MVP. Perth, Western Australia

Reply to group, rather than allenbrowne at mvps dot org.

Rita said:
Is it possible to open a form based on 2 criteria? Access 2003
automatically
walks you through design mode for opening a form, but it just allows you
to
select one criteria. This is my event procedure.

stDocName = "f Timesheet (Individual Client)"

stLinkCriteria = "[ClientID]=" & Me![ClientID]
DoCmd.OpenForm stDocName, , , stLinkCriteria

I would like it to also match up pay periods. I just copied and pasted
this,
but it didn't work. I'm not a programmer--I just cut and paste code:(

stDocName = "f Timesheet (Individual Client)"

stLinkCriteria = "[ClientID]=" & Me![ClientID]
stLinkCriteria = "[PayPeriodDate]=" & Me![PayPeriodDate]
DoCmd.OpenForm stDocName, , , stLinkCriteria

THANKS!!!!
 

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