Print Preview a Report Button

K

Keith

I added a Print Preview button with the wizard and modified it so that it
would only print the report for the record I was on, but I am having
problems.

My code is below.

The field containing the unique value of the record is
Code:
 and the first
record in the database (for example) contains the value A001 in this field.

However, when I click Print Preview, it asks for a parameter for A001 and I
have to enter the code I want to view the report for.

Why would this be?


Private Sub cmdPrintPreview_Click()
On Error GoTo Err_cmdPrintPreview_Click

Dim stDocName As String

stDocName = "Main Report"
DoCmd.OpenReport stDocName, acViewPreview, , "[Code] = " & Me![Code]

Exit_cmdPrintPreview_Click:
Exit Sub

Err_cmdPrintPreview_Click:
MsgBox Err.Description
Resume Exit_cmdPrintPreview_Click

End Sub
 
R

Reggie

Keith, to begin with it appears that Code is a text value so you will need to modify your code as
below:

DoCmd.OpenReport stDocName, acViewPreview, , "
Code:
 = '" & Me![Code] & "'"

It sounds like you may be using a query for the recordsource of the report and maybe have criteria
set for the Code field.  If so, you don't need the criteria using this method because you are
filtering when opening the report.  Another solution is you could add the criteria to the query and
not use the where clause when opening the report.  Simply type in the following for the criteria
under your Code field in your query

=Forms!frmYourForm![Code]

If Code field is in a subform use

=Forms!frmYourForm!frmYourSubform.Form.[Code]

Hope this helps!
 
K

Keith

Thank you

That worked fine.


Reggie said:
Keith, to begin with it appears that Code is a text value so you will need to modify your code as
below:

DoCmd.OpenReport stDocName, acViewPreview, , "
Code:
 = '" & Me![Code] & "'"

It sounds like you may be using a query for the recordsource of the report and maybe have criteria
set for the Code field.  If so, you don't need the criteria using this method because you are
filtering when opening the report.  Another solution is you could add the criteria to the query and
not use the where clause when opening the report.  Simply type in the following for the criteria
under your Code field in your query

=Forms!frmYourForm![Code]

If Code field is in a subform use

=Forms!frmYourForm!frmYourSubform.Form.[Code]

Hope this helps!

--
Reggie

----------
[QUOTE]
I added a Print Preview button with the wizard and modified it so that it
would only print the report for the record I was on, but I am having
problems.

My code is below.

The field containing the unique value of the record is [Code] and the first
record in the database (for example) contains the value A001 in this field.

However, when I click Print Preview, it asks for a parameter for A001 and I
have to enter the code I want to view the report for.

Why would this be?


Private Sub cmdPrintPreview_Click()
On Error GoTo Err_cmdPrintPreview_Click

Dim stDocName As String

stDocName = "Main Report"
DoCmd.OpenReport stDocName, acViewPreview, , "[Code] = " & Me![Code]

Exit_cmdPrintPreview_Click:
Exit Sub

Err_cmdPrintPreview_Click:
MsgBox Err.Description
Resume Exit_cmdPrintPreview_Click

End Sub
[/QUOTE]
[/QUOTE]
 

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