Many command Buttons: To only one Report?

  • Thread starter Thread starter an
  • Start date Start date
A

an

Hello!

I have many Command buttons on Form. Each one open a
Report based in correspondent query. Therefore many
Reports with same fields.
My question is:
Is possible to have only one Report and when I click
button 1, to load data query 1, or button 2 to load data
query 2, with same Report?
Thanks in advance.
an
 
Do you understand how a query can be set up with criteria to return
"filtered" results? It sounds like you should be able to work with one
report, one query, one button, and several controls that provide criteria
values for the query or report.
 
Assuming a form with controls:
txtStartDate
txtEndDate
cboCategory (for text field)
cboDeptID (for numeric field)
I would write code in the on click event of a single button:

Dim strWhere as String
strWhere = "1 = 1 "
If Not IsNull(Me.txtStartDate) Then
strWhere = strWhere & " AND DateField >=#" & _
Me.txtStartDate & "#"
End If
If Not IsNull(Me.txtEndDate) Then
strWhere = strWhere & " AND DateField <=#" & _
Me.txtEndDate & "#"
End If
If Not IsNull(Me.cboCategory) Then
strWhere = strWhere & " AND [Category] =""" & _
Me.cboCategory & """"
End If
If Not IsNull(Me.cboDeptID) Then
strWhere = strWhere & " AND [Dept] =" & _
Me.cboDeptID
End If
DoCmd.OpenReport "rptYourReport", acViewPReview, , strWhere
 
Ok, D Hookom.

Many, many thanks
an
-----Original Message-----
Assuming a form with controls:
txtStartDate
txtEndDate
cboCategory (for text field)
cboDeptID (for numeric field)
I would write code in the on click event of a single button:

Dim strWhere as String
strWhere = "1 = 1 "
If Not IsNull(Me.txtStartDate) Then
strWhere = strWhere & " AND DateField >=#" & _
Me.txtStartDate & "#"
End If
If Not IsNull(Me.txtEndDate) Then
strWhere = strWhere & " AND DateField <=#" & _
Me.txtEndDate & "#"
End If
If Not IsNull(Me.cboCategory) Then
strWhere = strWhere & " AND [Category] =""" & _
Me.cboCategory & """"
End If
If Not IsNull(Me.cboDeptID) Then
strWhere = strWhere & " AND [Dept] =" & _
Me.cboDeptID
End If
DoCmd.OpenReport "rptYourReport", acViewPReview, , strWhere


--
Duane Hookom
MS Access MVP


Sorry.
Where can I to look Examples, please?
Many thanks
an
criteria
to return to
work with one that
provide criteria


.
 
Back
Top