Open a Form Based on 2 Criteria?

  • Thread starter Thread starter Rita
  • Start date Start date
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!!!!
 
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
 
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!!!!
 
Back
Top