Discussion Locked

Access 2000 Reports

0 helpful
7 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

I have developed a form which lists all of my customer names and informations. Then at the bottom of the page I have subforms with each having their own underlying tables. Then I have showed relationships so when a certain custmomer in the main form is selected all the customers information in the tabbed sub forms appears. Everything works fine.

Here is the problem. I am wanting on my report to just print the information for that specific subform (one line of table) for that customer that is currently shown on the main form or screen. When I set up a print preview command it pulls every single line from the table and won't print just the current report that I have selected. So when I am wanting ot just have one report, I may have 30 reports appear and have to sift through each one to get to the one report I am actually after. If anyone has any ideas or found a solution to a similar problem your answers will be greatly appreciative.

Thanks.

7 replies

by peyison

There are a few ways to do this. The easiest is to link the report to the form. The Record Source of the report will contain the query from the table. In the Record Source query, set up a criteria for the Customer Id field based on the control on your form that contains the Customer Id (or whatever your key field is). For example, the Record Source query may look something like:

SELECT {field list} FROM tblCustInfo
WHERE CustId=[Forms]![frmTest]![tbxTest];

You can use the Expression Builder to do most of the work for you:

1) Open the report.

2) In the report properties, select the Record Source property.

3) Press the elipse button (...) to open the Query Builder.

4) Select the criteria field for the Customer ID field.
5) Press [CTRL] [F2] to open the Expression Builder.

6) In the left hand list box, select "Forms" and either "Loaded Forms" or "All Forms" depending on if your form is open, or not.

7) Select your form.

8) In the middle list box, select the control that contains the Customer Id - double click on it to load the entire source of the control into the top box.

9) Press OK.

10) This will create a criteria expression for the Customer ID field.

11) Save the Query and the Report.I will give another answer for a different way.

by peyison

Another option is to create the entire Record Source Query on the fly in code. This can be a good option if there are several fields on the form that you want to base the report on (e.g. a date range, a range of customers, region, etc.)

To do this, create your query in code - it will be a normal select statement. Then set the Record Source property of the report to this select statment:

'first, open the report and hide it
DoCmd.OpenReport rptCustReport, A_DESIGN
Reports(rptCustReport).Visible = False

'create the query string (tbxFromDate and tbxToDate are text boxes on your form)
sSql = "SELECT CustName, OrderNo, OrderDesc FROM tblCustInfo WHERE OrderDate Between #" & Me!tbxFromDate & "# AND #" & Me!tbxToDate & "# " & "GROUP BYCustName;"

'set the RecordSource property of the report
Reports(rptCustReport).RecordSource = sSql

'either open the report, or just print it, based on option buttons on your form

Select Case Me!obtOutput
Case 1 'Preview
DoCmd.OpenReport rptCustReport, A_PREVIEW

Case 2 'Print
DoCmd.OpenReport rptCustReport, A_NORMAL
CloseReport
End Select

'because you modified the report, Access will ask if you want to save changes - this CloseReport routine will prevent that

Sub CloseReport()
DoCmd.SetWarnings False
DoCmd.Close A_REPORT, gsReportName
DoCmd.SetWarnings True
End Sub

Hope this helps.

by mbarker734

Create a control button on your form and enter the following using the code builder of the On Click Event. Replace the needed names i.e. rptCustomer is your name for the report, Customer_Name is your ID field for the customer. The me! is refering to the current form.

Dim stDocName As String
Dim stLinkCriteria As String

stDocName = "rptCustomer"

stLinkCriteria = "[Customer_Name]=" & "'" & Me![Customer_Name] & "'"

DoCmd.OpenReport stDocName, acPreview, , stLinkCriteria

You can replace the acPreview with acNormal to cause the report to print with out openning in preview first.

Hope this helped.

Mark

This discussion is closed to new replies.