Re: Opening report from form
From: Allen Browne (AllenBrowne_at_SeeSig.Invalid)
Date: 05/22/04
- Next message: Allen Browne: "Re: Open new form based on 2 fields."
- Previous message: Steve Schapel: "Re: Esc Key"
- In reply to: Jim: "Opening report from form"
- Messages sorted by: [ date ] [ thread ]
Date: Sat, 22 May 2004 14:12:57 +0800
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
-- Allen Browne - Microsoft MVP. Perth, Western Australia. Tips for Access users - http://allenbrowne.com/tips.html Reply to group, rather than allenbrowne at mvps dot org. "Jim" <anonymous@discussions.microsoft.com> wrote in message news:107e801c43fbd$1ec93c50$a101280a@phx.gbl... > 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?
- Next message: Allen Browne: "Re: Open new form based on 2 fields."
- Previous message: Steve Schapel: "Re: Esc Key"
- In reply to: Jim: "Opening report from form"
- Messages sorted by: [ date ] [ thread ]