By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,573 Members | 907 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,573 IT Pros & Developers. It's quick & easy.

Can I Pass this Filter: ([Lookup_Field1].[Field1]="TYPE1"))) From Form to Report?

P: n/a
I have a form which lists studies. People can filter the form based
on
details about the study, such as the study type. Currently users
filter via
the right click method.

I would like to be able to have a report that shows just the filtered
records.

The code that I tried which didn't work:

Private Sub print_detail_Click()
On Error GoTo Err_print_detail_Click
DoCmd.Minimize
Dim stDocName As String
stDocName = "RptStudyInformationDetail"
'Debug.Print Me.Filter
'Debug.Print Me.RecordSource
DoCmd.openreport stDocName, acViewPreview, , Me.Filter, ,
Me.RecordSource
Reports!RptStudyInformationDetail.FilterOn = True
Exit_print_detail_Click:
Exit Sub

Err_print_detail_Click:
MsgBox Err.Description
Resume Exit_print_detail_Click

End Sub

The Debug Window read the following for Me.Recordsource:
SELECT TblMainStudyInformation.* FROM TblMainStudyInformation INNER
JOIN
[TblChoicesNames] ON TblMainStudyInformation.[Study Director] =
[TblChoicesNames].NameCode WHERE ((([last name] & ',' & [first
initial] &
[middle initial])='Smith,JM'));

And the following for Me.Filter:
((([Lookup_Test System].[Test System]="SYSTEMTYPE1"))) AND
((Lookup_Sponsor.Initials="RWW"))

Anybody have any idea how to make this work?

Thanks,
Beth

Mar 15 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Access 2002 and later produce this kind of Filter string when you filter on
a combo where the visible column is not the bound column.

You cannot pass that to the report directly, since the report doesn't
understand the "Lookup_Field" part. But there is a fudge. Create a query
that includes the lookup table, and *alias* it so that the name matches what
it's called in the Filter string. If the name matches, Access will be able
to make sense of it in the report.

To alias the table:
1. Open the query in design view.

2. Right-click the lookup table in the upper pane of query design, and
choose Properties.

3. Set the Alias property to:
Lookup_Field1
i.e. use exactly the same name as you see in your Filter string.

The OpenReport will then work.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

<em*********@snet.netwrote in message
news:11**********************@b75g2000hsg.googlegr oups.com...
>I have a form which lists studies. People can filter the form based
on
details about the study, such as the study type. Currently users
filter via
the right click method.

I would like to be able to have a report that shows just the filtered
records.

The code that I tried which didn't work:

Private Sub print_detail_Click()
On Error GoTo Err_print_detail_Click
DoCmd.Minimize
Dim stDocName As String
stDocName = "RptStudyInformationDetail"
'Debug.Print Me.Filter
'Debug.Print Me.RecordSource
DoCmd.openreport stDocName, acViewPreview, , Me.Filter, ,
Me.RecordSource
Reports!RptStudyInformationDetail.FilterOn = True
Exit_print_detail_Click:
Exit Sub

Err_print_detail_Click:
MsgBox Err.Description
Resume Exit_print_detail_Click

End Sub

The Debug Window read the following for Me.Recordsource:
SELECT TblMainStudyInformation.* FROM TblMainStudyInformation INNER
JOIN
[TblChoicesNames] ON TblMainStudyInformation.[Study Director] =
[TblChoicesNames].NameCode WHERE ((([last name] & ',' & [first
initial] &
[middle initial])='Smith,JM'));

And the following for Me.Filter:
((([Lookup_Test System].[Test System]="SYSTEMTYPE1"))) AND
((Lookup_Sponsor.Initials="RWW"))

Anybody have any idea how to make this work?

Thanks,
Beth
Mar 15 '07 #2

P: n/a
I must be missing something.

I have tried the suggestion several ways, and every time I get the
error message:

"Joined Table 'RptStudyInformationDetail' not listed in FROM clause"

Of course RptStudyInformationDetail isn't a table but instead the name
of my report. Is it not working because I am setting the recordsource
of the report on the open event?

I really appreciate the help!

Beth

Mar 15 '07 #3

P: n/a
Don't use the report name in the SQL statement.

To use an example from the Northwind sample database that installs with
Access, open the Orders form, select the Customer combo, and click the
Filter By Selection button on the toolbar. The Filter of the form will now
contain something like this:
([Lookup_CustomerID].[CompanyName]="Alfreds Futterkistez")

Now create a query, switch to SQL View, and paste this in:
SELECT Orders.*, Lookup_CustomerID.CompanyName
FROM Customers AS Lookup_CustomerID
INNER JOIN Orders ON Lookup_CustomerID.CustomerID = Orders.CustomerID
WHERE (Lookup_CustomerID.CompanyName="Alfreds Futterkistez");

Do you see that the Customers table has been aliased so that it matches the
name used in the Filter? If you now created a report based on this query,
the form's filter would work for the report also.

--
Allen Browne - Microsoft MVP. Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

<em*********@snet.netwrote in message
news:11**********************@e65g2000hsc.googlegr oups.com...
>I must be missing something.

I have tried the suggestion several ways, and every time I get the
error message:

"Joined Table 'RptStudyInformationDetail' not listed in FROM clause"

Of course RptStudyInformationDetail isn't a table but instead the name
of my report. Is it not working because I am setting the recordsource
of the report on the open event?

I really appreciate the help!

Beth
Mar 15 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.