Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing Only One Record in a Report via a Command Button/Macro 3

Status
Not open for further replies.

JerSand

Technical User
Oct 25, 2000
74
US
I have designed a form for use by eight people. I have also designed a report that exhibits all the fields.

Please assume a user is viewing a record in the Form. How could I enable the user to print the report for only that record? I have experimented with some Rube-Goldberg chains of filters, but so far, none of the command buttons with which I apply the filters provides the simple result I would like.

Thanks.

JerSand
 
I do this all the time. All you have to do is send a filter to the report when you call it. Put the following code in the command button on your form.

Dim stDocName As String
Dim LinkFilter As String

LinkFilter = "recordID = " & Me!recordId
stDocName = <your report name>
DoCmd.OpenReport stDocName, acviewnormal, , LinkFilter

(of course substitute your own field names in the LinkFilter line) B-)
 
Maquis, what is the &quot;&&quot; before the Me!RecordID mean? Just curious because I see that used and not sure what it means. I have used this method you posted but my syntax was different. Thanks for your help. Dawn
 
Dawn,
The &quot;&&quot; symbol just means &quot;and&quot;. Access uses it as a string concatenator. For example:

Name = me!Firstname & &quot; &quot; & me!MI & &quot; &quot; & Me!Lastname
 
Hello, Maquis.

Thanks so much for your expert instruction and quick response. Please excuse my delay in responding. I was out the door immediately after posting the SOS and didn't imagine I would obtain help so quickly. I'll give it a try, and judging from the responses you already received from others, I'm confident it will work fine.

Again, thanks.

JerSand
 
I knew it was a concatinator, I guess I was thrown off by it being placed within the &quot;quotes&quot;. I now realize that the quotes were just for the space inbetween the feilds. Sorry I was being lame. :)
 
Hi. I have similar problem: a master/detail form (order form with order items in detail) and I would like to print out the report based on this curently selected form. How?

the given solution:

Dim stDocName As String
Dim LinkFilter As String

LinkFilter = &quot;recordID = &quot; & Me!recordId
stDocName = <your report name>
DoCmd.OpenReport stDocName, acviewnormal, , LinkFilter

What should I put for recordID ? the primary key of curently selected record?
 
Yes, the primary key is usually placed there. If you only want to print 1 record on the report then just send it a filter which will return 1 record.
 
But how do I send a filter wich will return 1 record, and how does this filter know that I wanna print curently opened record? I guess I just don't get the point here.
 
Ok let's say you have a table with the following fields.

Table: Customer
CustomerId (Primary Key)
FirstName
LastName
StreetAddress
City
State
Zip

You also have a form which displays a customer record with text boxes named the same as the above fields and a report which prints a mailing label for a customer.

Let's say that you want to create a command button on the form which will print a mailing label for the current customer displayed. In the click event of the command button, you would put the code which was posted here earlier:

Dim stDocName As String
Dim LinkFilter As String

LinkFilter = &quot;CustomerId = &quot; & Me!CustomerId
stDocName = <your report name>
DoCmd.OpenReport stDocName, acviewnormal, , LinkFilter


me!CustomerId refers to the value in the current record of the CustomerId text box on the form.

The LinkFilter string is the same as the &quot;where&quot; portion of a query which will be passed to the filter of the report. This filter says to print only those customer records where the field CustomerId = the current customer id in the form.

You can refer to Access's help section for more details on the openreport statement.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top