By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
428,586 Members | 623 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 428,586 IT Pros & Developers. It's quick & easy.

Open report based on current record...

P: n/a
I've created a report for the purpose of printing a one page summary
of a record. Of course, when I created the report, it gives me a page
on every record. Can I create a button to open that report with just
the results of that current record? And how do I modify the report to
accept the buttons command?

Thanks!

Aug 8 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
On Wed, 08 Aug 2007 20:59:08 -0000, magmike wrote:
I've created a report for the purpose of printing a one page summary
of a record. Of course, when I created the report, it gives me a page
on every record. Can I create a button to open that report with just
the results of that current record? And how do I modify the report to
accept the buttons command?

Thanks!
Your table should have a unique prime key field.
In my example it is named [RecordID].

Add a command button to the form.
On the command button's property sheet write
[Event Procedure]
on the Click event line.
Then click on the little button with 3 dots that will appear on that
line.
When the code window opens, the cursor will be flashing between 2
already existing lines of code.
Between those 2 lines write:

DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport "ReportName", acViewPreview, , "[RecordID] = " &
[RecordID]

The above assumes a [RecordID] field that is a Number Datatype.

If, however, [RecordID] is Text Datatype, then use:

DoCmd.OpenReport "ReportName", acViewPreview, ,"[RecordID] = '" &
[RecordID] & "'"

as the Where clause.

For clarity, the single and double quotes are..
"[RecordID] = ' " & [RecordID] & " ' "
Change [RecordID] to whatever the actual field name is that you are
using.

See VBA Help files for:
Where Clause + Restrict data to a subset of records'
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
Aug 8 '07 #2

P: n/a
Beautiful. Thank you.

Now, when the report comes up, it comes up underneath my other form.
Is there a command I can use to bring it to the front as the final
action in that code?

On Aug 8, 4:07 pm, fredg <fgutk...@example.invalidwrote:
On Wed, 08 Aug 2007 20:59:08 -0000, magmike wrote:
I've created a report for the purpose of printing a one page summary
of a record. Of course, when I created the report, it gives me a page
on every record. Can I create a button to open that report with just
the results of that current record? And how do I modify the report to
accept the buttons command?
Thanks!

Your table should have a unique prime key field.
In my example it is named [RecordID].

Add a command button to the form.
On the command button's property sheet write
[Event Procedure]
on the Click event line.
Then click on the little button with 3 dots that will appear on that
line.
When the code window opens, the cursor will be flashing between 2
already existing lines of code.
Between those 2 lines write:

DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport "ReportName", acViewPreview, , "[RecordID] = " &
[RecordID]

The above assumes a [RecordID] field that is a Number Datatype.

If, however, [RecordID] is Text Datatype, then use:

DoCmd.OpenReport "ReportName", acViewPreview, ,"[RecordID] = '" &
[RecordID] & "'"

as the Where clause.

For clarity, the single and double quotes are..
"[RecordID] = ' " & [RecordID] & " ' "
Change [RecordID] to whatever the actual field name is that you are
using.

See VBA Help files for:
Where Clause + Restrict data to a subset of records'
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail

Aug 8 '07 #3

P: n/a
On Wed, 08 Aug 2007 21:20:24 -0000, magmike wrote:
Beautiful. Thank you.

Now, when the report comes up, it comes up underneath my other form.
Is there a command I can use to bring it to the front as the final
action in that code?

On Aug 8, 4:07 pm, fredg <fgutk...@example.invalidwrote:
>On Wed, 08 Aug 2007 20:59:08 -0000, magmike wrote:
>>I've created a report for the purpose of printing a one page summary
of a record. Of course, when I created the report, it gives me a page
on every record. Can I create a button to open that report with just
the results of that current record? And how do I modify the report to
accept the buttons command?
>>Thanks!

Your table should have a unique prime key field.
In my example it is named [RecordID].

Add a command button to the form.
On the command button's property sheet write
[Event Procedure]
on the Click event line.
Then click on the little button with 3 dots that will appear on that
line.
When the code window opens, the cursor will be flashing between 2
already existing lines of code.
Between those 2 lines write:

DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport "ReportName", acViewPreview, , "[RecordID] = " &
[RecordID]

The above assumes a [RecordID] field that is a Number Datatype.

If, however, [RecordID] is Text Datatype, then use:

DoCmd.OpenReport "ReportName", acViewPreview, ,"[RecordID] = '" &
[RecordID] & "'"

as the Where clause.

For clarity, the single and double quotes are..
"[RecordID] = ' " & [RecordID] & " ' "
Change [RecordID] to whatever the actual field name is that you are
using.

See VBA Help files for:
Where Clause + Restrict data to a subset of records'
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
If you are using Access 2000 or newer:

DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport "ReportName", acViewPreview, , "[RecordID] = " &
[RecordID]
Me.Visible = False
Then code the Report's Close event:
If Not CurrentProject.AllForms("YourFormName").IsLoaded Then
forms!YourFormName.Visible = True
End If

To make the form visible again when you close the report.
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail
Aug 8 '07 #4

P: n/a
Cool, thanks. Now I've tried replicating that by having a button once
pushed, open another form with that current records data in it. But
it's not working out the same! What's different?

mike

On Aug 8, 4:35 pm, fredg <fgutk...@example.invalidwrote:
On Wed, 08 Aug 2007 21:20:24 -0000, magmike wrote:
Beautiful. Thank you.
Now, when the report comes up, it comes up underneath my other form.
Is there a command I can use to bring it to the front as the final
action in that code?
On Aug 8, 4:07 pm, fredg <fgutk...@example.invalidwrote:
On Wed, 08 Aug 2007 20:59:08 -0000, magmike wrote:
I've created a report for the purpose of printing a one page summary
of a record. Of course, when I created the report, it gives me a page
on every record. Can I create a button to open that report with just
the results of that current record? And how do I modify the report to
accept the buttons command?
>Thanks!
Your table should have a unique prime key field.
In my example it is named [RecordID].
Add a command button to the form.
On the command button's property sheet write
[Event Procedure]
on the Click event line.
Then click on the little button with 3 dots that will appear on that
line.
When the code window opens, the cursor will be flashing between 2
already existing lines of code.
Between those 2 lines write:
DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport "ReportName", acViewPreview, , "[RecordID] = " &
[RecordID]
The above assumes a [RecordID] field that is a Number Datatype.
If, however, [RecordID] is Text Datatype, then use:
DoCmd.OpenReport "ReportName", acViewPreview, ,"[RecordID] = '" &
[RecordID] & "'"
as the Where clause.
For clarity, the single and double quotes are..
"[RecordID] = ' " & [RecordID] & " ' "
Change [RecordID] to whatever the actual field name is that you are
using.
See VBA Help files for:
Where Clause + Restrict data to a subset of records'
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail

If you are using Access 2000 or newer:

DoCmd.RunCommand acCmdSaveRecord
DoCmd.OpenReport "ReportName", acViewPreview, , "[RecordID] = " &
[RecordID]
Me.Visible = False

Then code the Report's Close event:
If Not CurrentProject.AllForms("YourFormName").IsLoaded Then
forms!YourFormName.Visible = True
End If

To make the form visible again when you close the report.
--
Fred
Please respond only to this newsgroup.
I do not reply to personal e-mail- Hide quoted text -

- Show quoted text -

Aug 9 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.