Print button problem

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

Guest

I have print buttons on all my forms, for easy printing for users. They all
work fine except on one form. I use the same code for all of them:

On Error GoTo Err_Command5_Click

Dim stDocName As String

stDocName = "Report Name"
DoCmd.OpenReport stDocName, acPreview

Exit_Command5_Click:
Exit Sub

Err_Command5_Click:
MsgBox Err.Description
Resume Exit_Command5_Click

On one form, based on a parameter query, when I click the print button it
asks for the parameter value again even though the correct record is already
being displayed. How do I get it to just print the record without asking for
the parameter again? Also, I need it to always print this report in landscape
mode but it defaults to portrait and I don't know how to change it.
 
Dino,

A parameter query will always prompt for a value whenever it's opened. To
print the current record, either:

1) Specify criteria in your query equal to the value of a form control:

=Forms![YourForm]![YourControl]

2) Use the optional Where clause with the OpenReport method:

Dim stDocName As String
Dim stWhere As String

stDocName = "YourTable"
stWhere = "[YourField] =" & Me![YourFormControl]
DoCmd.OpenReport stDocName, acPreview, , stWhere

To permanently change the layout of your report, choose File, Page Setup
from report design view, select the Page tab, then the Landscape button. You
can also do it programmatically at runtime. See the following link:

http://office.microsoft.com/en-us/assistance/HA010345531033.aspx

Hope that helps.
Sprinks
 
Thanks!

Sprinks said:
Dino,

A parameter query will always prompt for a value whenever it's opened. To
print the current record, either:

1) Specify criteria in your query equal to the value of a form control:

=Forms![YourForm]![YourControl]

2) Use the optional Where clause with the OpenReport method:

Dim stDocName As String
Dim stWhere As String

stDocName = "YourTable"
stWhere = "[YourField] =" & Me![YourFormControl]
DoCmd.OpenReport stDocName, acPreview, , stWhere

To permanently change the layout of your report, choose File, Page Setup
from report design view, select the Page tab, then the Landscape button. You
can also do it programmatically at runtime. See the following link:

http://office.microsoft.com/en-us/assistance/HA010345531033.aspx

Hope that helps.
Sprinks


Dino said:
I have print buttons on all my forms, for easy printing for users. They all
work fine except on one form. I use the same code for all of them:

On Error GoTo Err_Command5_Click

Dim stDocName As String

stDocName = "Report Name"
DoCmd.OpenReport stDocName, acPreview

Exit_Command5_Click:
Exit Sub

Err_Command5_Click:
MsgBox Err.Description
Resume Exit_Command5_Click

On one form, based on a parameter query, when I click the print button it
asks for the parameter value again even though the correct record is already
being displayed. How do I get it to just print the record without asking for
the parameter again? Also, I need it to always print this report in landscape
mode but it defaults to portrait and I don't know how to change it.
 
When I tried to type in the code exactly as you indicated, I get a compile
error after the "&".



Sprinks said:
Dino,

A parameter query will always prompt for a value whenever it's opened. To
print the current record, either:

1) Specify criteria in your query equal to the value of a form control:

=Forms![YourForm]![YourControl]

2) Use the optional Where clause with the OpenReport method:

Dim stDocName As String
Dim stWhere As String

stDocName = "YourTable"
stWhere = "[YourField] =" & Me![YourFormControl]
DoCmd.OpenReport stDocName, acPreview, , stWhere

To permanently change the layout of your report, choose File, Page Setup
from report design view, select the Page tab, then the Landscape button. You
can also do it programmatically at runtime. See the following link:

http://office.microsoft.com/en-us/assistance/HA010345531033.aspx

Hope that helps.
Sprinks


Dino said:
I have print buttons on all my forms, for easy printing for users. They all
work fine except on one form. I use the same code for all of them:

On Error GoTo Err_Command5_Click

Dim stDocName As String

stDocName = "Report Name"
DoCmd.OpenReport stDocName, acPreview

Exit_Command5_Click:
Exit Sub

Err_Command5_Click:
MsgBox Err.Description
Resume Exit_Command5_Click

On one form, based on a parameter query, when I click the print button it
asks for the parameter value again even though the correct record is already
being displayed. How do I get it to just print the record without asking for
the parameter again? Also, I need it to always print this report in landscape
mode but it defaults to portrait and I don't know how to change it.
 
I re-typed it and the compile error went away. But when I run the print
action, if I use my table as the docname it says a report of that name doesnt
exist.


Sprinks said:
Dino,

A parameter query will always prompt for a value whenever it's opened. To
print the current record, either:

1) Specify criteria in your query equal to the value of a form control:

=Forms![YourForm]![YourControl]

2) Use the optional Where clause with the OpenReport method:

Dim stDocName As String
Dim stWhere As String

stDocName = "YourTable"
stWhere = "[YourField] =" & Me![YourFormControl]
DoCmd.OpenReport stDocName, acPreview, , stWhere

To permanently change the layout of your report, choose File, Page Setup
from report design view, select the Page tab, then the Landscape button. You
can also do it programmatically at runtime. See the following link:

http://office.microsoft.com/en-us/assistance/HA010345531033.aspx

Hope that helps.
Sprinks


Dino said:
I have print buttons on all my forms, for easy printing for users. They all
work fine except on one form. I use the same code for all of them:

On Error GoTo Err_Command5_Click

Dim stDocName As String

stDocName = "Report Name"
DoCmd.OpenReport stDocName, acPreview

Exit_Command5_Click:
Exit Sub

Err_Command5_Click:
MsgBox Err.Description
Resume Exit_Command5_Click

On one form, based on a parameter query, when I click the print button it
asks for the parameter value again even though the correct record is already
being displayed. How do I get it to just print the record without asking for
the parameter again? Also, I need it to always print this report in landscape
mode but it defaults to portrait and I don't know how to change it.
 
Back
Top