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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Linking filtered records (only) to a report form

Status
Not open for further replies.

slammer2

Technical User
Oct 23, 2001
4
US
How is data from only filtered records (from a given table) linked to the report form for that table? Example: I have 200 records in Table1--by filtering (i.e., by date) I now have 25 records--how is it that I can have only the data from the 25 records show up in the report already linked (through queries) to Table1--not all 200 records?
 
Filter the query by using the criteria cells in query design mode "The Key, The Whole Key, and Nothing But The Key, So Help Me Codd!"
 
There is two possible solution.
first one:
If the table has 200 entry that should matches your criteria but the query is showing only 25 then in the design view of the query look at the toolbar you shoul see 25 in a combo box (near the center of the tool bar). Change that to 'all'. This will solve that problem. What its doing is displaying only the top 25 records.

Next one:
If the above is not the problem then it will take a little investigating to find it.
1)check the button that calls the form for the criteria.
2)check the filter property of the report
3)verify the record source for the report is correct.
4)check the code on_format of the detail section of the report.

If none of these help let me know.
 
Slammer2 received two very considerate responses from 930driver and Nordyck. However, he asked the wrong question. He wants to know how he can link only the filtered records to an existing table--so that only the data from the filtered records show up in the report (and not the data from all the records).
 
Slammer2

See below for an exerpt from Microsoft Knowledge Base on how to print a report from your records in a filter by form. The link takes you to the article where you can download a sample db demonstrating this procedure.

Good Luck :-9


This example uses the sample database Northwind.mdb. The technique involves creating a new form and a new report. The form uses event procedures to apply a filter and to open the new report. The report uses the Filter property to apply the same filter that is used in the form.




Open the sample database Northwind.mdb.


Use the AutoReport: Tabular Wizard to create a new report based on the Customers table. Close and save the report as rptCustomers.


Use the AutoForm: Tabular Wizard to create a new form based on the Customers table. Close and save the form as frmFilterForm.


Open frmFilterForm in Design view. Increase the size of the form footer section so that it can hold three command buttons.


Create a command button in the form footer and set its properties as follows:

Name: cmdOpenReport
Caption: Open Report
OnClick: [Event Procedure]

Set the OnClick [Event Procedure] as follows:

Private Sub cmdOpenReport_Click()
If Me.Filter = "" Then
MsgBox "Apply a filter to the form first"
Else
DoCmd.OpenReport "rptCustomers", A_PREVIEW, , Me.Filter
End If
End Sub



Create a second button in the form footer and set its properties as follows:

Name: cmdClearFilter
Caption: Clear Filter
OnClick: [Event Procedure]

Set the OnClick [Event Procedure] as follows:

Private Sub cmdClearFilter_Click()
Me.Filter = ""
End Sub



Create a third button in the form footer and set its properties as follows:

Name: cmdClose
Caption: Close
OnClick: [Event Procedure]

Set the OnClick [Event Procedure] as follows:

Private Sub cmdClose_Click()
DoCmd.Close acForm, Me.Form.Name
End Sub



Set the following properties for the frmFilterForm form:

OnOpen: [Event Procedure]
OnClose: [Event Procedure]

Set the form's OnOpen [Event Procedure] as follows:

Private Sub Form_Open(Cancel as Integer)
Me.Filter = ""
End Sub

Set the form's OnClose [Event Procedure] as follows:

Private Sub Form_Close()
DoCmd.Close acReport, "rptCustomers"
End Sub



Switch the form to Form view.


On the toolbar, click the Filter By Form button to set a filter, and then click the Apply Filter button to apply the filter.


Click the Open Report button on the form. A report should appear with the same filter that was applied to the form.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top