Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Print report from current record on form 1

Status
Not open for further replies.

goslincm

MIS
May 23, 2006
292
US
Hi, I have a form with a couple of subforms. Main form is frm_employees with subform frm_vouchers and frm_expenses.

When I am in the voucher form, I have a button to print a voucher report but I'm not getting the report to display only my current voucher.

I was using: [forms]![frm_vouchers]![voucher_id] in my query but that is not working.
 
You need to either include the name of the subform control, for example:

[tt][forms]![frm_employees ]![Name of subform control].Form![voucher_id][/tt]

Or use the Where argument of DoCmd.Openreport.

 
Remou, I guess I spoke too soon. When I try this:

Private Sub Command16_Click()
Dim StDocName As String

StDocName = "rpt_travel_expense_report"
DoCmd.OpenReport StDocName, acViewPreview, [voucher_id] = "'" & Me![voucher_id] & "'"
End Sub

It still does not work. What have I done wrong?
 
You seem to be short of a comma and over on quotes:

[tt]DoCmd.OpenReport StDocName, acViewPreview,, [voucher_id] = '" & Me![voucher_id] & "'"[/tt]
 
And I'm placing this on the OnClick event of my button correct?
 
That's right. Are you sure Voucher_Id is a text field?
 
No, voucher_id is not a text field, its an autonumberfield
 
Ah, well in that case, get rid of the quotes:

[tt]DoCmd.OpenReport StDocName, acViewPreview,, [voucher_id] = " & Me![voucher_id][/tt]
 
Private Sub Command16_Click()

DoCmd.OpenReport "rpt_travel_expense_report", acViewPreview, , [voucher_id] = " & Me![voucher_id]"
End Sub


I'm having a bad day here, as this is not working.
 
You are not the only one! Please excuse the mistakes:

DoCmd.OpenReport "rpt_travel_expense_report", acViewPreview, , [COLOR=red yellow]"[/color][voucher_id] = " & Me![voucher_id]
End Sub

That is:
[tt]DoCmd.OpenReport "rpt_travel_expense_report", acViewPreview, , "[voucher_id] = " & Me![voucher_id][/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top