Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Report on a single record

Status
Not open for further replies.

matpj

Technical User
Mar 28, 2001
687
GB
Can anyone tell me, what to do to be able to have a button on a form, that prints a report on that current record?
 
Hi Mat,
Something like:

DoCmd.OpenReport "YourReportName", acViewPreview, , "[AnIDOfTheReport]=[Forms]![TheFormNameYouAreOn]![TheIDOnTheForm]"

should do. Gord
ghubbell@total.net
 
sorry to be a pain, but I dont know much about coding etc.
do I need to create a query first or anything? or is it just a standard report?
and where do I type that code you mentioned?
 
In this case no.
You can use a wizard to create a command button to open the report. Then take a look at the buttons "on click" event in visual basic (event procedure) then "..." beside. Note how the code has been built for you and modify it to similar as above. :) Gord
ghubbell@total.net
 
Was glad to find this post. However, I can't seem to get the code to work. I have the command button-no problem. I can't get it to return just the one record. Does the form have to be set to data entry or anything? Further instruction would be helpful. Thanks
 
Hi mp,
No difference regarding how the form is set, just as long as there is data in/on the form. Take care to watch all those commas and double-check the names of the field you are trying to address. If you have trouble with this method, instead use the query that is the Record Source of the report, and using the 'builder', add the criteria under the appropriate field in the query. You'll get the same result and then all you would need is:

DoCmd.OpenReport "YourReportName", acViewPreview

in the Visual Basic code. :) Gord
ghubbell@total.net
 
Go to the Northwind database and look at the Orders Form in Design view, see code for the Print Invoice button. See the linked query.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top