Printing the current record

D

Dan Goble

You guys rule...!
I am getting it done here better than anywhere I have tried.

Next problem:

I have a form open with all the information filled in to a record to be
printed to a report that is actually a contract. I want to populate the
fields in the report with only the info from the current record Name etc. I
have inserted the controls in the contract (report) and they show fine. The
problem is that there are previous records and the thing wants to print only
the last record. How do I print from that form with just the record that I
am looking at? Or I guess I should say the current record.
Thanks
Dan
 
F

fredg

You guys rule...!
I am getting it done here better than anywhere I have tried.

Next problem:

I have a form open with all the information filled in to a record to be
printed to a report that is actually a contract. I want to populate the
fields in the report with only the info from the current record Name etc. I
have inserted the controls in the contract (report) and they show fine. The
problem is that there are previous records and the thing wants to print only
the last record. How do I print from that form with just the record that I
am looking at? Or I guess I should say the current record.
Thanks
Dan

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

Add a command button to your 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'
 

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