Print current record on specific report

spectraflame

Well-known Member
Joined
Dec 18, 2002
Messages
829
Office Version
  1. 365
Platform
  1. Windows
I have a form that allows for entry of service order information. I currently have a print button at the bottom of the form, but when I click it, it is printing the form that is open which I guess that it what is suppose to be doing.

What I would like to do is to print the current record information on a specific report that I have created. I would still like to have a print button at the bottom of the entry form screen, but I need the record printed like the report instead of like the form layout.

Does this make sense?
Matthew
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
I think what you're looking to do is have the Print button on the Form that will print the current record (being viewed) on a specific Report.

What I have done is create a Command Button that when clicked runs a Macro who's (only) Action is OpenReport and in the arguements are Report Name, myreport; View, Print; and the rest left as default.

Hope that's what you're looking for.
 
Upvote 0
You can pass the criteria to the report to syncronise it to your form with this syntax
DoCmd.OpenReport "MyReport", A_NORMAL, "MyReportsQuery", "[TableID]=[Forms]![MyForm]![TableID] "
Check in help for more details.
You will probably need to save the record first if you are doing data entry or the new details won't be in the table!

DoCmd.DoMenuItem acFormBar, acRecordsMenu, acSaveRecord

peter
 
Upvote 0
Can I have the DoCmd that will save the record along with the code to print the current record attached to the same button? Meaning that when I click the print button, it will save the data for the current record and then print out the record.

I think I understand everything about the OpenReport command except for the MyReportsQuery part. Are you saying that in order to just print the current record, I will need to have a unique query defined?

Thanks again. It is all slowly coming together.
Matthew
 
Upvote 0
It is OK to use the same button, just save before print, the query bit you can probably leave blank, it is there to give you more choices but you probably don't need it. (but leave it's comma there!)

DoCmd.OpenReport "MyReport", A_NORMAL, ,"[TableID]=[Forms]![MyForm]![TableID] "

HTH

Peter
 
Upvote 0
bat17,

This is what I am using:

DoCmd.OpenReport "ElectricWO", A_NORMAL, "[ElectricWO]=[Forms]![ElectricWO]![ElectricWO] "

I just realized that naming the report the same at the table can be a bit confusing. Anyway, it does print, but it is printing every record in the database instead of just the current one.

Any thoughts?
Matthew
 
Upvote 0
you missed the comma
DoCmd.OpenReport "ElectricWO", ,A_NORMAL, "[ElectricWO]=[Forms]![ElectricWO]![ElectricWO] "


Peter
 
Upvote 0
My mistake. I even missed that after you warned me to leave it in.

So now my statement is as follows:

DoCmd.OpenReport "ElectricWO", , A_NORMAL, "[ElectricWO]=[Forms]![ElectricWO]![ElectricWO] "

Now when I click the button to print, it is prompting me to key in a Parameter Value from the table. I must have something really screwed up now.
 
Upvote 0
it looks as if your criteria is screwy unless you really have confussed things with same names :)

DoCmd.OpenReport "ElectricWO", , A_NORMAL, "[ElectricWO]=[Forms]![ElectricWO]![ElectricWO] "

The bold bits should be the fields that have the matching data to restrict the number of records, I expect it is the keyfield for the table in this case.


Peter
 
Upvote 0
I have yet to get this to print a single record. I have gone through the entire process again by removing all of the code and recreating the print button on the form again. I was just wanting to make sure that I had my syntax correct. Below is the complete code for the print button that is on my form. I have changed the names of the tables, forms, and reports to make them much easier to tell apart.

Private Sub Print_Current_Record_Click()
On Error GoTo Err_Print_Current_Record_Click

Dim stDocName As String

stDocName = "WorkOrderRpt"
DoCmd.OpenReport stDocName, acNormal
DoCmd.OpenReport "WorkOrderrpt", , A_NORMAL, " [WorkOrdertbl] =[Forms]![WorkOrderfrm]! [WorkOrdertbl] "


Exit_Print_Current_Record_Click:
Exit Sub

Err_Print_Current_Record_Click:
MsgBox Err.Description
Resume Exit_Print_Current_Record_Click

End Sub
 
Upvote 0

Forum statistics

Threads
1,214,912
Messages
6,122,200
Members
449,072
Latest member
DW Draft

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top