How to print current record in report format

Mansoor Ahmad

Registered User.
Local time
Today, 10:59
Joined
Jan 20, 2003
Messages
140
Dear All

On my form I want to add a button that when clicked would print the current record on form in a report format not in form view format. So that I can choose which fields to print for that record.

How can I do it?

Thanks
 
Create your report. Put a command button on your form with code similar to this:

DoCmd.OpenReport "ReportNameHere", , ,"[ID] = " & Me![ID]

Replace the Me![ID] with the name of the control on your form with the records unique identifier and the [ID] with then name of your unique identifier of the Record Source for the form. The code above assumes a numeric ID....

hth,
Jack
 
A little more help

Thank you very much for your help. I have tried to do it as you suggested but because I am not very good in using codes so actually could not exactly work it out. I used this code in OneClick event of command button. It did print the report but just column headings, no data. Would it work like as follows

DoCmd.OpenReport "ReportNameHere", , ,"[WR LABEL NO] = " & Me![WR LABEL NO]

Hope you would not mind to explain a bit more.

To make things easier for myself, I explain here my situation. I have a form based on a query. In the underlying table, field Barcode No is unique for each record. Where in this code would I use this field. What I want is that when I am inputing data into form, I want that specific record to be printed just on the click of a button.

Thanks again for you time. Looking forward to your reply.
 
You have a query that is the Record Source for you form. Use that same query as the Record Source for your report. You can use the Wizard to create the report for you if you like. In the code below where it says "ReportNameHere" replace that with actual name of your report. If you report were named rptMyReport then the code would look like this:

DoCmd.OpenReport "rptMyReport", , ,"[WR LABEL NO] = " & Me![WR LABEL NO]

Next is to replace WR LABEL NO with the name of the BarCode field unless WR LABEL NO is the name of the BarCode field in your table and the name of the control on your form that has the BarCode. Once you have that you should be good to go....

hth,
Jack
 
I think a little more help needed

Thank you very much for you help again.

It is still not working as I wanted. I cannot understand where I am doing wrong?

I have created a report (Report1) base on the same query on which the form is based on. On OnClick event procedure of a command button I have put following code

Private Sub Command145_Click()
DoCmd.OpenReport "Report1", , , "[ID]=" & Me![ID]
End Sub

ID is the primary key fied in my trial table. The field properly of ID is set to Autonumer. When I click on command button, it prompts with following error

'Run time error 3075
Extra ) in query expression '([ID])''

As I mentioned earlier I don't know much about codes. When I clicked on &Me![ID], it showed a screen tip as '&Me![ID]=Null', when I added =Null towards the end and clicked on command button it started printing all the records in form.

I hope you wold not mind to give some more advise. Thanks

Looking forward to your reply.:(
 
You must have the ID field on your form as well. The Me![ID] is looking for a control on your form called ID and in that control contains the ID from the table. If you click on the Field List icon you should see the ID field in the list. If it is there then drag it to you form. If it is not there then your form is based on a query and you need to add the ID field to the query so it can be added to your form. Once you have the ID on the form the code will work.

Good luck!

Jack
 
Thank you very much

Jack

Thank you very much for your help. I have tried it and it worked just like the way I wanted. You were right ID field was not there on form.

Thank you very much for your time and valuable help.

Mansoor

;) :)
 
Mansoor -

You are welcome. Continued success with your project.

Jack
 

Users who are viewing this thread

Back
Top Bottom