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!

Still problems with printing only curently selected record via report

Status
Not open for further replies.

MarkoKobal

IS-IT--Management
Jul 18, 2001
14
SI
Hi! I already started a thread on this theme, but still havent solved my problem. A have a Master/Detail form wich uses two tables linked throuhg primary key. (it's an order form with many order items in child fields). I have also a report with the same stile, and I print this report with command button, from form, but it prints all the records, however I would like to print only the curently selected. How?
Please help!
 
Why not try:

Matching the key field on the form with the key field on the report via the query?

All you have to do is:
Open the form in design view.
Open the report in design view.
Open the query for the report in design view.

Now - In the conditions statement on your key field, use the expression builder to find the correct field on your form.

Now your report is linked to the current record on the form, because all the records that don't match the key field are dismissed.

This is how I do it every time, and it usually works first time too!


HTH

Andrew.
 
For my example I will assume you have a field called OrderID and a control on your main form called txtOrderID. The OrderID is the primary key that links an order (one) to it's detail (many) items, and that it is a Number field type. I'm assuming that you want to view an order on the screen and then print that record/order using your report which now prints all records. I assume that you already have a button on your order form that calls the report up and shows you the report with ALL orders showing. (I would not have to assume as much if relevant data were included in the post, sorry.)

Look at the code for the print report button, you'll see a couple lines like this:
[tt]
Dim stDocName As String

stDocName = "MyReportName"
DoCmd.OpenReport stDocName, acPreview
[/tt]

The DoCmd.OpenReport command allows you to specify a where clause which allows you to limit a report being called to certain data "where x = y". We're going to modify this code to do that by changing it to this:

[tt]
Dim stDocName As String
Dim stDocWhere As String

stDocName = "MyReportName"
stDocWhere = "[OrderID] = " & txtOrderID

DoCmd.OpenReport stDocName, acPreview, , stDocWhere
[/tt]

Notice that I set the where clause to [OrderID] which is your fieldname = to the control on the form [txtOrderID]. Then I add the where claus to the OpenReport command.

HTH
Joe Miller
joe.miller@flotech.net
 
Thanks guys, now it works just the way I wanted. Thank you very much!

Marko.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top