Report Question

G

Guest

Yesterday, I asked:
I have a report that would use one of two queries, depending on the status of
a field in the main database table.
The field in the table is called "In-House", and is set as a Yes/No field.
What I want to be able to do, is, upon opening the report, to have it check
that field, and if it is Yes then it would run query1. If it is no, then it
would run query2.
Is there a way to do this?

and was told:
By code you can set recordsource

if In-House = 0 then
reports("YourReport").recordsource = query1
else
reports("YourReport").recordsource = query2
end if

I entered the code in the report open as:
If In_House = 0 Then
DoCmd.OpenReport "testreport2", acViewPreview, "test1"
Else
DoCmd.OpenReport "testreport1", acViewPreview, "test2"
End If

I have the record source for the report set to a query titled 'test' that
has the field In_House in the query. I have a parameter setup that asks me
the "status" of In_House that I want.
Every time that I run it, the report testreport2 is opening.

Any possible suggestions?
However, whenever I run the query
 
G

Guest

Not sure if it is just a typing mistake but the top code has in (dash) house
and the bottom code has in (underscore) house which will always be zero
because it is undefined and will therefore always run testreport2
 
D

Duane Hookom

I don't think you can get the value of In_House in the On Open event of the
report. You must find a way to get the value of In_House from some place
other than the report's record source. Once your report has retrieved a
value from its record source, I believe it is too late to set its record
source property.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top