Question

G

Guest

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?
 
M

MA

Steve said:
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?


By code you can set recordsource

if In-House = 0 then
reports("YourReport").recordsource = query1
else
reports("YourReport").recordsource = query2
end if
--
_ _
Ciao
MAssimiliano Amendola www.accessgroup.it
Cisa - Conferenza Italiana per Sviluppatori Access
Info: www.donkarl.com/it
 
B

Bob Howard

The report will need to have its recordsource initially set to a query that
contains In_House as a field. So in the OnOpen event, you can simply test
(If In_House) and then set the recordsource property accordingly. Bob.
 
G

Guest

using the code as written return a Type Mismatch or Compile error on the line
if In-House = 0 then
suggestions?
 
D

Duane Hookom

You code reads like " If In minus House = 0 Then"
Try not to use "-" in field or any other names. You might be able to use
if [In-House] = 0 then
 
M

MA

Duane said:
You code reads like " If In minus House = 0 Then"
Try not to use "-" in field or any other names. You might be able to
use if [In-House] = 0 then

Sorry steve,
In also for this reason that it's best not to use minus sign but under_score
--
_ _
Ciao
MAssimiliano Amendola www.accessgroup.it
Cisa - Conferenza Italiana per Sviluppatori Access
Info: www.donkarl.com/it
 
G

Guest

OK. I wonder if I am doing something wrong.
I have changed my naming for In-House to In_House. Entered the sample code
in the report open, and made the changes needed to the report name and query
names.
The report will open, but it does not appear to be pulling my data. I am
getting a #Name? error on every field.

Any suggestions?

MA said:
Duane said:
You code reads like " If In minus House = 0 Then"
Try not to use "-" in field or any other names. You might be able to
use if [In-House] = 0 then

Sorry steve,
In also for this reason that it's best not to use minus sign but under_score
--
_ _
Ciao
MAssimiliano Amendola www.accessgroup.it
Cisa - Conferenza Italiana per Sviluppatori Access
Info: www.donkarl.com/it
 
D

Duane Hookom

Are you attempting to change the record source of the report with code in
the report that looks at a field value in the report's record source?

--
Duane Hookom
MS Access MVP


Steve Voorhees said:
OK. I wonder if I am doing something wrong.
I have changed my naming for In-House to In_House. Entered the sample code
in the report open, and made the changes needed to the report name and
query
names.
The report will open, but it does not appear to be pulling my data. I am
getting a #Name? error on every field.

Any suggestions?

MA said:
Duane said:
You code reads like " If In minus House = 0 Then"
Try not to use "-" in field or any other names. You might be able to
use if [In-House] = 0 then

Sorry steve,
In also for this reason that it's best not to use minus sign but
under_score
message using the code as written return a Type Mismatch or Compile error on
the line
if In-House = 0 then
suggestions?

:

Steve Voorhees wrote:
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?


By code you can set recordsource

if In-House = 0 then
reports("YourReport").recordsource = query1
else
reports("YourReport").recordsource = query2
end if
--
_ _
Ciao
MAssimiliano Amendola www.accessgroup.it
Cisa - Conferenza Italiana per Sviluppatori Access
Info: www.donkarl.com/it

--
_ _
Ciao
MAssimiliano Amendola www.accessgroup.it
Cisa - Conferenza Italiana per Sviluppatori Access
Info: www.donkarl.com/it
 
G

Guest

yes. I have 2 different queries that run on the same report. I want to make
it so that they don't have to end up trying to choose which report they want
to run.
Basically, what I want it to do is that if In_House=0 then it would change
the recordsource for the report to a particular query, say test1. However,
if In_House= anything other than 0 it would change the record source to the
query test2.

Duane Hookom said:
Are you attempting to change the record source of the report with code in
the report that looks at a field value in the report's record source?

--
Duane Hookom
MS Access MVP


Steve Voorhees said:
OK. I wonder if I am doing something wrong.
I have changed my naming for In-House to In_House. Entered the sample code
in the report open, and made the changes needed to the report name and
query
names.
The report will open, but it does not appear to be pulling my data. I am
getting a #Name? error on every field.

Any suggestions?

MA said:
Duane Hookom wrote:
You code reads like " If In minus House = 0 Then"
Try not to use "-" in field or any other names. You might be able to
use if [In-House] = 0 then

Sorry steve,
In also for this reason that it's best not to use minus sign but
under_score


message using the code as written return a Type Mismatch or Compile error on
the line
if In-House = 0 then
suggestions?

:

Steve Voorhees wrote:
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?


By code you can set recordsource

if In-House = 0 then
reports("YourReport").recordsource = query1
else
reports("YourReport").recordsource = query2
end if
--
_ _
Ciao
MAssimiliano Amendola www.accessgroup.it
Cisa - Conferenza Italiana per Sviluppatori Access
Info: www.donkarl.com/it

--
_ _
Ciao
MAssimiliano Amendola www.accessgroup.it
Cisa - Conferenza Italiana per Sviluppatori Access
Info: www.donkarl.com/it
 

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