PDA

View Full Version : Create button to print current record in report view.



candie213
09-30-2010, 07:35 AM
I have set up a POS system. I would like to create a button that would print the report(receipt) for the current record.

This is what I have so far....

Private Sub Command47_Click()
DoCmd.Save acForm, "Orders"
If Me.Dirty Then Me.Dirty = False
DoCmd.SelectObject acReport, "CashInvoice", True
DoCmd.PrintOut , , , , 2
End Sub

I created a button to pull the report but it doesn't automatically print the current record. I have the query set up behind the report to ask for which record to print.

hansup
09-30-2010, 08:22 AM
I created a button to pull the report but it doesn't automatically print the current record. I have the query set up behind the report to ask for which record to print.Consider using DoCmd.OpenReport with a WhereCondition. But first make a copy of your CashInvoice report, CashInvoice2, which doesn't ask for which record to print.

This example assumes the current record has a numeric primary key field named "id", and a text box control named "txtid" bound to that field.

Private Sub Command47_Click()
'* DoCmd.Save acForm saves design changes to the form
'* uncomment the next line if that's what you really want
'DoCmd.Save acForm, "Orders"
If Me.Dirty Then Me.Dirty = False
DoCmd.OpenReport "CashInvoice2", acViewNormal, WhereCondition:="id = " & Me.txtid
End Sub

candie213
09-30-2010, 08:40 AM
I tried and this part is not working...

DoCmd.OpenReport "CashInvoice", acViewNormal, WhereCondition:="Order ID = " & Me.Order ID

hansup
09-30-2010, 09:11 AM
I tried and this part is not working...

DoCmd.OpenReport "CashInvoice", acViewNormal, WhereCondition:="Order ID = " & Me.Order ID Use square brackets around any field/control names which include spaces.
DoCmd.OpenReport "CashInvoice", acViewNormal, WhereCondition:="[Order ID] = " & Me.[Order ID]

candie213
09-30-2010, 12:13 PM
Yes, that worked! Thanks!!!!

hansup
09-30-2010, 12:19 PM
Good! That's what I hoped to hear.

Maybe someday, if you have a tolerant sense of humor, I'll whip out my rant about Hanzi's Field Name Rules, and how you broke them by including a space in your field name.

OTOH, maybe I should just keep my mouth shut about Hanzi Rules and drink more beer instead. :whistle:

Cheers.