Filter in reports

SofiaFreitas

New member
Local time
Today, 00:28
Joined
Jun 2, 2009
Messages
6
Hi!

I would like to create a report from the filtered records in a form. I mean, I have a form where I can choose only the parameters I want to see. When clicking a button I want that just the records i've filtered in the form appear in the report. how can I do that?
 
use code:

docmd.openreport "Reportname",, acViewPreview,,[fieldname] = Forms![formname]![controlname on form]

The fieldname argument is the name of a field in the underlying table or query of the report you want to open. The controlname on form argument is the name of the control on the form that contains the value you want records in the report to match.
 
I've used construction like this in my code:
Code:
DoCmd.OpenReport "repResenje1", acViewPreview, , Me.[txtMaticniBroj] = Forms![frmPregled]![txtMaticniBroj]
The code is bind to a button on the form an its OnCLick event.
Me.[txtMaticniBroj] is the control on the Report and Forms![frmPregled]![txtMaticniBroj] is the path to the control on the Form.

When the report opens it displays all records from linked table (with workers) but what I want to show is only data from one record (the one I'm currently at before I click a button to open report). How do I do that?

I've added this constructions for the purpose of code debugging:

The one is after the DoCmd.OpenReport:
Code:
MsgBox "Me.txtMaticniBroj&" = "&Forms![frmPregled]![txtMaticniBroj]"

And the other two are in front of the DoCmd.OpenReport:
Code:
MsgBox Me.txtMaticniBroj
MsgBox Forms![frmPregled]![txtMaticniBroj]

The first two message boxes each display the result "1111111111112" which is correct, but the third message box is displaying "False". Why is the comparement of these two records False when they are the same?
The field that contains this data "1111111111112" in the table is textfield not number.
 
Last edited:
I've solved the problem by adding a hidden field which holds the primary key field data [intZaposleniID].
Then I created a query which records I wanted to display.
After that I've entered this code in button's OnClick event (the button on form that opens the report):
Code:
Private Sub btnReportOpen1_Click()
DoCmd.OpenReport "repResenje1", acViewPreview, "qryZaposleni", "[qryZaposleni]![intZaposleniID]=" & [Forms]![frmPregled]![intZaposleniID]
End Sub

So the problem for me was that I tried to compare the non-Primary Key data field, in DoCmd.OpenReports WHERE clause, but as soon as I entered the check for Primary Key field the "Datatype Mismatch" error was gone.

Hope I've helped someone in the future wit similar problem.
 

Users who are viewing this thread

Back
Top Bottom