Command Button to Preview/Print Report

  • Thread starter Thread starter teelee
  • Start date Start date
T

teelee

Hello, I have a Form and a Subform I'm trying to add a command button on the
bottom of the subform so when the Customer's show up on the subform I would
like to preview/print the Report for that specified customer. Is there a way
of doing this?


Thanks in Advance
 
Hello "teelee".

teelee said:
Hello, I have a Form and a Subform I'm trying to add a command
button on the bottom of the subform so when the Customer's show
up on the subform I would like to preview/print the Report for
that specified customer. Is there a way of doing this?

Yes, I think so, if the subform is in continuous or single form view.
Fom the orms design view, You can use the command button wizard to
create VBA code that opens your report (designed to show all customers)
in print preview mode.
You then have to change the code such that the variable stLinkCriteria
will contain the criterion that will filter the report data for only
the one customer displayed on the form, something like this:
stLinkCriteria = "[CustomerID]=" & Me.CustomerID
Insert a line like this before the DoCmd.OpenReport command.
 
You don't have to have a button in the subform, teelee, unless you
particularly want one.

A button on the main form can include the code

Dim MyCust As Long

MyCust = Me.[YourSubFormName].Form.[CustID]
'replace the names in square brackets by the real name of your subform and
customer field
DoCmd.OpenReport "YourReport",acPreview,,"[CustID]=" & MyCust

(this assumes that the customer field is a number field - the syntax is
different for text)

Evi
 
I tried both ways and it's still not working. I added a command button to my
main form "Orders by Customer" subform named Subfrm Orders Listing entered
the code and I still can't get the report to open to select customer.

Thanks

Wolfgang Kais said:
Hello "teelee".

teelee said:
Hello, I have a Form and a Subform I'm trying to add a command
button on the bottom of the subform so when the Customer's show
up on the subform I would like to preview/print the Report for
that specified customer. Is there a way of doing this?

Yes, I think so, if the subform is in continuous or single form view.
Fom the orms design view, You can use the command button wizard to
create VBA code that opens your report (designed to show all customers)
in print preview mode.
You then have to change the code such that the variable stLinkCriteria
will contain the criterion that will filter the report data for only
the one customer displayed on the form, something like this:
stLinkCriteria = "[CustomerID]=" & Me.CustomerID
Insert a line like this before the DoCmd.OpenReport command.
 
Hello "teelee".

teelee said:
teelee said:
Hello, I have a Form and a Subform I'm trying to add a command
button on the bottom of the subform so when the Customer's show
up on the subform I would like to preview/print the Report for
that specified customer. Is there a way of doing this?

Yes, I think so, if the subform is in continuous or single form
view. Fom the orms design view, You can use the command button
wizard to create VBA code that opens your report (designed to show
all customers) in print preview mode.
You then have to change the code such that the variable
stLinkCriteria will contain the criterion that will filter the
report data for only the one customer displayed on the form,
something like this:
stLinkCriteria = "[CustomerID]=" & Me.CustomerID
Insert a line like this before the DoCmd.OpenReport command.
I tried both ways and it's still not working. I added a command
button to my main form "Orders by Customer" subform named
Subfrm Orders Listing entered the code and I still can't get the
report to open to select customer.

Please privide some information:
What's the name of the control that contains the customerid in the
formthat contains the button? Please post the code of that button.
And what's the name of the field in the datasource of the report
that contains the customerid? And finally: What's it's datatype?
I think with all this information, we must be able to make it work.
 
Back
Top