DoCmd.OpenReport

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

Guest

I need to open a report based on two conditions. One condition is a user's
name, which is provided from a listbox on a form. The other condition is a
start date(sd) and end date(ed), which are provided from two calendar
controls on a form. I am trying to use the code below to open the report but
it doesn't work. Do you know how I can open a report using the conditions
stated?

sd = Form_Calendar.beg_date
ed = Form_Calendar.end_date

strLinkCriteria = "[BG_Responsible]=" & "'" & Me.List54.Value & "'"
strReportCriteria = "[HS_CHANGE_DATE] between #" & sd & "# and #" & ed & "#"

DoCmd.OpenReport stDocName, acViewPreview, strReportCriteria, strLinkCriteria
 
Combine the two criteria into a single clause:

sd = Form_Calendar.beg_date
ed = Form_Calendar.end_date

strLinkCriteria = "[BG_Responsible]='" & Me.List54.Value & "' And " & _
"[HS_CHANGE_DATE] between #" & sd & "# and #" & ed & "#"

DoCmd.OpenReport stDocName, acViewPreview, , strLinkCriteria
 
Ken, thanks. Your tip worked great.

Ken Snell (MVP) said:
Combine the two criteria into a single clause:

sd = Form_Calendar.beg_date
ed = Form_Calendar.end_date

strLinkCriteria = "[BG_Responsible]='" & Me.List54.Value & "' And " & _
"[HS_CHANGE_DATE] between #" & sd & "# and #" & ed & "#"

DoCmd.OpenReport stDocName, acViewPreview, , strLinkCriteria

--

Ken Snell
<MS ACCESS MVP>



Lewis M said:
I need to open a report based on two conditions. One condition is a user's
name, which is provided from a listbox on a form. The other condition is a
start date(sd) and end date(ed), which are provided from two calendar
controls on a form. I am trying to use the code below to open the report
but
it doesn't work. Do you know how I can open a report using the conditions
stated?

sd = Form_Calendar.beg_date
ed = Form_Calendar.end_date

strLinkCriteria = "[BG_Responsible]=" & "'" & Me.List54.Value & "'"
strReportCriteria = "[HS_CHANGE_DATE] between #" & sd & "# and #" & ed &
"#"

DoCmd.OpenReport stDocName, acViewPreview, strReportCriteria,
strLinkCriteria
 
Back
Top