Limit report to 1 record

T

Tina

I maybe doing this all wrong but what I want to do is have users enter data
in a form. Once done entering the data then they would click on a button to
open a report w/ only the data they entered. For example say they entered
data about a sale made the report would then be a detailed receipt for that 1
sale.
Currently I created a form w/ a button to open a print preview of a report.
When the report opens it contains all records instead of just one.
Can I do this in access using forms or reports?
If so how?
Thanks
 
F

fredg

I maybe doing this all wrong but what I want to do is have users enter data
in a form. Once done entering the data then they would click on a button to
open a report w/ only the data they entered. For example say they entered
data about a sale made the report would then be a detailed receipt for that 1
sale.
Currently I created a form w/ a button to open a print preview of a report.
When the report opens it contains all records instead of just one.
Can I do this in access using forms or reports?
If so how?
Thanks

First create a report that displays all of the data you want to show.

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

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
 
T

Tina

Thank you!
That worked perfect.

fredg said:
I maybe doing this all wrong but what I want to do is have users enter data
in a form. Once done entering the data then they would click on a button to
open a report w/ only the data they entered. For example say they entered
data about a sale made the report would then be a detailed receipt for that 1
sale.
Currently I created a form w/ a button to open a print preview of a report.
When the report opens it contains all records instead of just one.
Can I do this in access using forms or reports?
If so how?
Thanks

First create a report that displays all of the data you want to show.

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

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
 

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

Similar Threads


Top