Print preview a filtered report .

G

Ghost

How do you print preview a filtered report. I wrote the following code but
it does not work. Any assitstance is greatly appreciated: My form is
called: BONDS and my report is called BONDS.

___________________________________________________________

If Not IsNull(Me.Filter) Then
DoCmd.OpenReport "Bonds", A_PREVIEW, , Me.Form.BONDS
DoCmd.Maximize 'Maximize the report window.

Else
MsgBox "Apply a filter to the form first"
End If


_________________________________________________________
 
T

TomInQ8

You have to first establish what it is you are filtering for. What
field in the report can you link to your form for a filter criteria?

Make a button to run the report. Put this in the sub for the onclick
event:

Private Sub MyButton_Click()
On Error GoTo Err_MyButton_Click

Dim stDocName As String
Dim stLinkCriteria As String

stLinkCriteria = "[field name in report]= '" & Me![field name in form]
& "'"
stDocName = "Bonds"

DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria

Exit_MyButton_Click:
Exit Sub

Err_MyButton_Click:
MsgBox Err.Description
Resume Exit_MyButton_Click

This will link the report to the record you have open in your form and
will eliminate your need to filter the form before running the report.
If the value you are linking is numeric, you will have to edit the link
criteria line as follows:

stLinkCriteria = "[field name in report]=" & Me![field name in form]
 
G

Ghost

Thanks all for most helpful comments.

This is what I did.

If Not IsNull(Me.Filter) Then
DoCmd.OpenReport "BONDS", A_PREVIEW, , Me.Form.Filter
DoCmd.Maximize 'Maximize the report window.
Else
MsgBox "Apply a filter to the Form first"
End If


This worked. I just changed the Me.form.Bond to Me.form.Filter.

All worked great.

Thanks once again for timely and professional assistance.
 
G

Ghost

Thanks all for great comments. I changed the entry in docmd from
Me.Form.bonds to Me.Form.Filter and all worked great.

Really appreciate your timeliness and suggestions.




Me.Form.Filter
 

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