tdjfdjdj
tdjfdjdj

Reputation: 2471

use form variable in access report (DoCmd.OpenReport)

I am trying to pass a variable (part of the sql where clause) to populate a report. No error, but report seems to be ignoring my variables value.

DoCmd.OpenReport "report111", acViewPreview, , "[a].[fname] = 'oasgjasgip'"

I should get 0 zero results back, but i still get 3 rows.

id fname lname
--------------
1 mike lee
2 jon  thomas
3 bob  newman

Here is my query behind the report:

select distinct a.fname,b.lname from table1 a left join table2 b on a.id=b.id

Upvotes: 1

Views: 1529

Answers (1)

JeffO
JeffO

Reputation: 8043

You're refering to a field with a table alias. The report is not going to be aware of that.

Try:

DoCmd.OpenReport "report111", acViewPreview, , "[fname] = 'oasgjasgip'" 

Or replace [a] with the actual name of the table especially if [fname] appears more than once.

Upvotes: 2

Related Questions