Printing a report from a form (current record) in MS Access

wwwredback

Registered User.
Local time
Today, 09:14
Joined
Apr 28, 2009
Messages
37
Hello All, I have a form in MS Access that I want to fill out like an invoice and then print just that particular order using a report but I can't seem to get it to work.

Can someone help please?

Here is the code I am using from a command button to open the report but it shows errors for the fields:

Sub PrintInvoice_Click()

Dim strDocName As String
Dim strWhere As String
strDocName = "Orders"
strWhere = "[OrderID]=" & Me!OrderID
DoCmd.OpenReport strDocName, acPreview, , strWhere

End Sub

Thanks in advance.
 
strDocName = "Orders"

Is "Orders" the name of your report?
Is OrderID text or a number?

If OrderID is a number then your code look OK if it is text it is incorrect.

If it is may I suggest that you name
reports with prefix of rpt
forms with frm
tables with tbl
queries with qry.

Here is an old sample of mine that may help you.
 
Last edited:
Hi John,

Thank you so much for your help.

Very, very helpful reply!!

Thanks again.

James.
 
James,

Thanks for your nice reply, I'm glad you go it working.

Let us know what was the fault in your code?

Sometimes, you explaining what the fix was and what was wrong with the original code helps other users with similar problems.
 
Hi John,

Sorry I thought I had it but it now shows a dialog box asking for a parameter value.

Why is this?

Thanks a million.

James.
 
James,

Post a copy of your database (with any sensitive data removed) and I or someone will have a look at the problem.
 
If you're inputing the invoice data then trying to print it out I suspect that the record hasn't been saved at this point. Try inserting the line

If Me.Dirty Then Me.Dirty = False

just prior to the line that opens the report.
 
James,

What missinglinq posted makes a lot of sense, if you have not "saved" the record before you try to print it you will get an error.

If you have a look at the code in my sample behind the "Print Report" button you will see this code;
Code:
' it will not have been "saved" so this will do it.

If Me.Dirty Then
Me.Dirty = False
End If

Give that a try first and then if that fails, yes you can PM me.
 
Hi There John,

I'm getting in a bit of a muddle with this.

Do you have an email address so I can attach it and send it through to you.

With the PM I can't seem to attach a file.

Thanks again for all your help.

James.
 
James,

Post if here, so if I can't help you someone else will.
 
When clicking the print invoice button it is asking for a value

your code is
StrCriterion = "[CustomerID]=" & Me![CustomerID]

it should be

StrCriterion = "[CustomerID]='" & Me![CustomerID] & "'"

Anyway this will print all invoices for that customer, surely you want to set the criteria to Invoice number = nnn

David
 
James,

Here it is back and working.

The mistake you made was copying my code and not making changes to suit your database.

I changed CustomerID to OrderID and I changed the Name of you report to Rpt_Invoice and in my code I changed Rpt_Customer to Rpt_Invoice.

Good luck with the rest of your project, I am now of to bed.
 

Attachments

Hi John,

Just wanted to say a really big thank you for all your help on this one. It has been bugging me for a while and now you have fix it.

So thanks a million.

James.
 
James,

Your most welcome, glad to be able to help.
 

Users who are viewing this thread

Back
Top Bottom