Printing only filtered data in a form

  • Thread starter Thread starter Printing only filtered data in a form
  • Start date Start date
P

Printing only filtered data in a form

Hi all-

I'm of new to Access 2007. I have created a form and a report. Is it
possible to have the user use the built in filter Access provides and click
the report button and print only that data. Each time I open the form
different data will need to be selected by the user.
 
For a simple filter, you can just use the form's Filter string as the
WhereCondition for OpenReport.

This example assumes a command button named cmdPreview, that is to open
Report1 filtered the same way as the form:

Private Sub cmdPreview_Click()
Dim strWhere As String
If Me.Dirty Then Me.Dirty = False
If Me.FilterOn Then strWhere = Me.Filter
DoCmd.OpenReport "report1", acViewPreview, , strWhere
End Sub

It can get more complex where combos are involved. Post back if you have
difficulties.

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

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

"Printing only filtered data in a form" <Printing only filtered data in a
(e-mail address removed)> wrote in message
news:[email protected]...
 
Allen Browne said:
For a simple filter, you can just use the form's Filter string as the
WhereCondition for OpenReport.

This example assumes a command button named cmdPreview, that is to open
Report1 filtered the same way as the form:

Private Sub cmdPreview_Click()
Dim strWhere As String
If Me.Dirty Then Me.Dirty = False
If Me.FilterOn Then strWhere = Me.Filter
DoCmd.OpenReport "report1", acViewPreview, , strWhere
End Sub

It can get more complex where combos are involved. Post back if you have
difficulties.

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

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

"Printing only filtered data in a form" <Printing only filtered data in a
(e-mail address removed)> wrote in message

Try this one, I know it is a bit complicated but you can use any queries or
sql statements to filter report data.

Private Sub Trip_Sheet_Click()

If Forms!frmTripheader!tabTripHeaderID <> "" Then
Call Fuel_Click
rep = "Trip Sheet"
repname = "repTripSheet"
repquery = strSQL
reptitle = "Trip Sheet"
Call OpenReport(rep, repquery, reptitle, repname)
Else
MsgBox ("Please chose trip"), vbInformation, "Trip Sheet"

End If

End Sub


repquery = "select * from tabtripheader where tabtripheaderid = " & Forms
 
I tried the example code but there's no action when I click on the
(cmdPreview button.) I replaced "report1" with my report's name.
 
Is the code running at all?
To find out, you could add this line to the top of the procedure:
MsgBox "cmdPreview_Click is doing something."

If it is not working at all, you may need to add your database's folder to
the trusted locations under:
Office Button | Access Options | Trust Center | Trust Center Settings

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

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

"Printing only filtered data in a form"
 
When I click the button - even with ( MsgBox "cmdPreview_Click is doing
something.") the filter and paste buttons located at the top tool bar grays
out.
 
Does the MsgBox() pop up?

- No: set the trust centre options.

- Yes: Enter Stop on the next line. When it stops, press F8 to trace what's
going on.

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

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

"Printing only filtered data in a form"
 
Hey Allen Browne-

Thank You!!!! It works now!! You have been very helpful!
 
Back
Top