Opening report from form

J

Jim

I have a form called Receipts & Disbursements which
contains two subforms, Accounts subform and Entries
subform. Accounts subform is linked to Receipts &
Disbursements form via a matter id number and Entries
subform is linked to Accounts via an account id number.
Thanks to help from people at this site, that all works
fine. I move the focus to an account in the Accounts
subform and all of the entries for that account appear on
the Entries subform--very cool. I want to open a
Receipts & Disbursements Report, limited to whatever
account has the focus in the Accounts subform, via a
command button on the Receipts & Disbursements Form.
Currently, I do this by placing a parameter criteria in
the query upon which the Receipts & Disbursements Report
is based, using to the account number currently active
on the Entries subform. However, I would rather not "tie
up" the query and the report in this way. I'd like to
have the option of opening the report from other places,
using other devices, as needed. (a) Is there a way to
open the report to the record with the focus, other than
what I'm doing now,without resorting to VB--I'm pretty
weak with it; (b) if the answer to (a) is no, is there
some code I can add to the current command button
language that will accomplish what I'm seeking to do?; or
(c) is there another solution?

Thank you in advance.

Jim
 
A

Allen Browne

Use the WhereCondition of the OpenReport action to limit the report to the
current record in the form.

This example assumes the form has a numeric field named "ID" that uniquely
identifies the record to print. Use the code in the Event Procedure for the
Click event of a command button named "cmdPrint".

Private Sub cmdPrint_Click()
Dim strWhere As String
If Me.Dirty Then 'Save first
Me.Dirty = False
End If
If Me.NewRecord Then 'Check there is a record to print
MsgBox "Pick a record."
Else
strWhere = "[ID] = " & Me.ID
DoCmd.OpenReport "MyReport", acViewPreview, , strWhere
End If
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top