Question

Locked

printing current form to report

By dj_4rce ·
i have a problem with my project with ms access 2007, i cannot print the current form into report and there is a pop-up message saying like this one once i click the print button that created (not with the wizard):

"The microsoft office access database engine could not find the oblect '[MarriageID]=&Me.[MarriageID]". Make sure the object exists and that you spell its name and the path name correctly." i checked this out but then once i click the button printing process does not proceed;

here's the code:

Private Sub cmdPrint_Record_Click()
On Error GoTo Err_cmdPrint_Record_Click

Dim stDocName As String

stDocName = "MarriageReport"
DoCmd.OpenReport stDocName, acViewPrint, "[MarriageID]=& Me. [MarriageID]"

Exit_cmdPrint_Record_Click:
Exit Sub

Err_cmdPrint_Record_Click:
MsgBox Err.Description
Resume Exit_cmdPrint_Record_Click

End Sub

please with this project... thanks

This conversation is currently closed to new comments.

3 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Answers

Collapse -

Print from a Microsoft Access Form into a Report.

You may, at times, wish to only print the record that you are currently displaying in your Microsoft Access form. This can be done directly from the Form's File ? Print Option and choosing Print Range ? Selected Record(s).
However, forms are not really optimized to print out records and you may wish to present your data in a more user friendly approach.
Question ? From a command button on my form, is it possible to print a report of only the current record?
Answer ? Yes, You will need to define a WHERE clause in the DoCmd.OpenReport method
Syntax:
DoCmd.OpenReport reportname [, view][, filtername][, wherecondition]
For Example:
DoCmd.OpenReport "rptEmployeeDetails", acViewPreview, , _
"[lngEmpID]=Forms!frmEmployee
The first section DoCmd. OpenReport "rptEmployeeDetails",acViewPreview can be broken down as:
DoCmd.OpenReport is opening the report - "rptEmployeeDetails".
acViewPreview is opening the report in Print Preview mode.
The last section enclosed in the double quotes is the criteria which can be broken down as:
[lngEmpID] is the name on the unique fieldname of the record that identifies the record you want to print - it could be the Primary Key.
Forms!frmEmployeeDetails !lngEmpID is the place where the value of lngEmpID is to be found. In this case, On a form called 'frmEmployeeDetails' in a control called 'lngEmpID'
This method assumes that the record has already been selected on a form prior to printing. The Report name here is "rptEmployeeDetails".
http://www.databasedev.co.uk/print_form_record.html

Please post back if you have any more problems or questions.

Collapse -

problem?

by fadz007 In reply to Print from a Microsoft Ac ...

Hello,
I am trying to print current record using the vba code you've provided and making changes to the names accordingly.

My code is:


Private Sub cmdPrint_Click()
'Print current record
'using rptCustomerOrder.
If IsNull(Me!CustomerID) Then
MsgBox "Please select a valid record", _
vbOKOnly, "Error"
Exit Sub
End If
DoCmd.OpenReport "rptCustomerOrder", acViewPreview, , _
"CustomerID = Forms!frmCustomerOrder"
End Sub

However, when i click the print button, an error message pops up
"the object you have referenced as OLE isn't an OLE object"
Any ideas what this means?

Plus, this prints all the records.

Thank you.

Back to Software Forum
3 total posts (Page 1 of 1)  

Related Discussions

Related Forums