create a report based on 30 queries

D

davidstevans

Hi all,

I am trying to create a report based on 30 queries . These 30 queries
are based on one table. When I use the Report wizard and select more
than one query I get the message " You have chosen fields from record
source which the wizard can't connect. You may have chosen fields from
a table and from a query based on that table. If so try choosing
fields from only tha table or only the query".

I do not know what to do.? Any guidance will help

thanks,

Dave
 
D

davidstevans

Jeff Queries are like below:

SELECT Min(MailDate) FROM YourTable

What is the oldest maildate with an operator assigned to it.

SELECT Min(MailDate) FROM YourTable WHERE Operator is Not Null

What is the oldest maildate without an operator assigned to it

SELECT Max(MailDate) FROM YourTable WHERE Operator is Null

What is the oldest maildate for the current year

SELECT Min(MailDate) FROM YourTable WHERE [Year] = "07"

What is the oldest maildate for the prior years(anything that is not


SELECT Min(MailDate) FROM YourTable WHERE [Year] <> "07"

What is the oldest maildate where data in CURRENT starts with 714.

SELECT Min(MailDate) FROM YourTable WHERE [CURRENT] Like "714*"

, How many records are between 0 to 30 days with an operator.

SELECT Count(*) FROM YourTable WHERE [Days] Between 0 and 30
and
Operator is not Null
 
K

krissco

Jeff Queries are like below:

SELECT Min(MailDate) FROM YourTable

What is the oldest maildate with an operator assigned to it.

SELECT Min(MailDate) FROM YourTable WHERE Operator is Not Null

What is the oldest maildate without an operator assigned to it

SELECT Max(MailDate) FROM YourTable WHERE Operator is Null

What is the oldest maildate for the current year

SELECT Min(MailDate) FROM YourTable WHERE [Year] = "07"

What is the oldest maildate for the prior years(anything that is not

SELECT Min(MailDate) FROM YourTable WHERE [Year] <> "07"

What is the oldest maildate where data in CURRENT starts with 714.

SELECT Min(MailDate) FROM YourTable WHERE [CURRENT] Like "714*"

, How many records are between 0 to 30 days with an operator.

SELECT Count(*) FROM YourTable WHERE [Days] Between 0 and 30
and
Operator is not Null

If there is a way to combine any of the queries - this will make
things more efficient for you.

That being said, I don't particularly like having 30+ single-use
objects in my databases. I would write a function to return a scalar
and bind the calling of that function to a control in your report.

What I mean is this:

'Call this function like so: =getMyScalar("Count(*)", "YourTable",
"[Days] Between 0 and 30"
Public Function getMyScalar(strAggregate as String, strTable as
String, optional strWhere as String) as Variant

'Some Variables
dim rst as New ADODB.Recordset
dim strSql as String

strSql = "Select " & strAggregate & " From " & strTable

'Fix the where clause - "LIKE" bombs w/ vba - use ALIKE instead.
'After fixing, append to strSql
if strWhere <> "" then

if instr(1, strWhere, "like") <> 0 then
strWhere = Replace(strWhere, "alike", "like")
strWhere = Replace(strWhere, "like", "alike")
strWhere = Replace(strWhere, "*", "%")
strWhere = Replace(strWhere, "?", "_")
'If you use other wildcards in your "like" comparisons, you will
want to address them here too.
end if

strSql = strSql & " Where " & strWhere

end if

'Open the query and return the scalar
rst.Open strSql, currentProject.connection
if not rst.eof then
getMyScalar = rst(0)
end if

'Cleanup
if not rst is nothing then
if rst.state = adstateopen then rst.close
set rst = nothing
end if

end function

Can you create a report with no recordsource? I guess I've never
tried. . . You could call this function from many textboxes and have
the single scalar show on your report. This is still not efficient (as
it will execute a single query for every text box) but it saves you
some clutter.

PS. You will probably want to save yourself some hassle and remove my
"LIKE" re-formatting. If that is the case, just make sure that the
strWhere you pass in uses ALIKE with the standard SQL wildcards.

-Kris
 
J

Jeff Boyce

David

So it sounds like your "30 queries" are each returning a single value.

Another approach might be to create a report that is not bound to any query,
then use controls in the report to "get" the individual values using the
DMax(), or DMin(), or DCount() functions.

Regards

Jeff Boyce
Microsoft Office/Access MVP
 
D

davidstevans

David

So it sounds like your "30 queries" are each returning a single value.

Another approach might be to create a report that is not bound to any query,
then use controls in the report to "get" the individual values using the
DMax(), or DMin(), or DCount() functions.

Regards

Jeff Boyce
Microsoft Office/Access MVP




Jeff Queries are like below:
SELECT Min(MailDate) FROM YourTable
What is the oldest maildate with an operator assigned to it.
SELECT Min(MailDate) FROM YourTable WHERE Operator is Not Null
What is the oldest maildate without an operator assigned to it
SELECT Max(MailDate) FROM YourTable WHERE Operator is Null
What is the oldest maildate for the current year
SELECT Min(MailDate) FROM YourTable WHERE [Year] = "07"
What is the oldest maildate for the prior years(anything that is not
SELECT Min(MailDate) FROM YourTable WHERE [Year] <> "07"
What is the oldest maildate where data in CURRENT starts with 714.
SELECT Min(MailDate) FROM YourTable WHERE [CURRENT] Like "714*"
, How many records are between 0 to 30 days with an operator.
SELECT Count(*) FROM YourTable WHERE [Days] Between 0 and 30
and
Operator is not Null

Thank you for all you help . I am using the dcount function. I need
help with this query:

ELECT Count(*) FROM YourTable WHERE [Days] Between 0 and 30
and Operator is not Null

this is what i have. but is not working.

=DCount("[DAYS]","YourTable","[OPER] is Not Null & [days] Between 0
And 30 ")

thanks
 
K

krissco

So it sounds like your "30 queries" are each returning a single value.
Another approach might be to create a report that is not bound to any query,
then use controls in the report to "get" the individual values using the
DMax(), or DMin(), or DCount() functions.

Jeff Boyce
Microsoft Office/Access MVP
Jeff Queries are like below:
SELECT Min(MailDate) FROM YourTable
What is the oldest maildate with an operator assigned to it.
SELECT Min(MailDate) FROM YourTable WHERE Operator is Not Null
What is the oldest maildate without an operator assigned to it
SELECT Max(MailDate) FROM YourTable WHERE Operator is Null
What is the oldest maildate for the current year
SELECT Min(MailDate) FROM YourTable WHERE [Year] = "07"
What is the oldest maildate for the prior years(anything that is not
SELECT Min(MailDate) FROM YourTable WHERE [Year] <> "07"
What is the oldest maildate where data in CURRENT starts with 714.
SELECT Min(MailDate) FROM YourTable WHERE [CURRENT] Like "714*"
, How many records are between 0 to 30 days with an operator.
SELECT Count(*) FROM YourTable WHERE [Days] Between 0 and 30
and
Operator is not Null

Thank you for all you help . I am using the dcount function. I need
help with this query:

ELECT Count(*) FROM YourTable WHERE [Days] Between 0 and 30
and Operator is not Null

this is what i have. but is not working.

=DCount("[DAYS]","YourTable","[OPER] is Not Null & [days] Between 0
And 30 ")

thanks



=DCount("[DAYS]","YourTable","[OPER] is Not Null and [days] Between 0
And 30 ")


-Kris
 
D

davidstevans

David
So it sounds like your "30 queries" are each returning a single value.
Another approach might be to create a report that is not bound to any query,
then use controls in the report to "get" the individual values using the
DMax(), or DMin(), or DCount() functions.
Regards
Jeff Boyce
Microsoft Office/Access MVP

Jeff Queries are like below:
SELECT Min(MailDate) FROM YourTable
What is the oldest maildate with an operator assigned to it.
SELECT Min(MailDate) FROM YourTable WHERE Operator is Not Null
What is the oldest maildate without an operator assigned to it
SELECT Max(MailDate) FROM YourTable WHERE Operator is Null
What is the oldest maildate for the current year
SELECT Min(MailDate) FROM YourTable WHERE [Year] = "07"
What is the oldest maildate for the prior years(anything that is not
SELECT Min(MailDate) FROM YourTable WHERE [Year] <> "07"
What is the oldest maildate where data in CURRENT starts with 714.
SELECT Min(MailDate) FROM YourTable WHERE [CURRENT] Like "714*"
, How many records are between 0 to 30 days with an operator.
SELECT Count(*) FROM YourTable WHERE [Days] Between 0 and 30
and
Operator is not Null
Thank you for all you help . I am using the dcount function. I need
help with this query:
ELECT Count(*) FROM YourTable WHERE [Days] Between 0 and 30
and Operator is not Null
this is what i have. but is not working.
=DCount("[DAYS]","YourTable","[OPER] is Not Null & [days] Between 0
And 30 ")

=DCount("[DAYS]","YourTable","[OPER] is Not Null and [days] Between 0
And 30 ")

-Kris

Kris, thanks for the last one, how about this one:


SELECT Count(*)
FROM mydata
WHERE (((mydata.CURRENT) Like "714*") And ((myddata.OPER) Is Not Null)
And ((mydata.DAYS) Between 0 And 10));


=DCount("[CURRENT] like ''714*' ")","myddata","[OPER] is Not Null and
[days] Between 0 And 10 ")
 
K

krissco

On Aug 30, 8:32 am, (e-mail address removed) wrote:
David
So it sounds like your "30 queries" are each returning a single value.
Another approach might be to create a report that is not bound to any query,
then use controls in the report to "get" the individual values using the
DMax(), or DMin(), or DCount() functions.
Regards
Jeff Boyce
Microsoft Office/Access MVP

Jeff Queries are like below:
SELECT Min(MailDate) FROM YourTable
What is the oldest maildate with an operator assigned to it.
SELECT Min(MailDate) FROM YourTable WHERE Operator is Not Null
What is the oldest maildate without an operator assigned to it
SELECT Max(MailDate) FROM YourTable WHERE Operator is Null
What is the oldest maildate for the current year
SELECT Min(MailDate) FROM YourTable WHERE [Year] = "07"
What is the oldest maildate for the prior years(anything that is not
SELECT Min(MailDate) FROM YourTable WHERE [Year] <> "07"
What is the oldest maildate where data in CURRENT starts with 714.
SELECT Min(MailDate) FROM YourTable WHERE [CURRENT] Like "714*"
, How many records are between 0 to 30 days with an operator.
SELECT Count(*) FROM YourTable WHERE [Days] Between 0 and 30
and
Operator is not Null
Thank you for all you help . I am using the dcount function. I need
help with this query:
ELECT Count(*) FROM YourTable WHERE [Days] Between 0 and 30
and Operator is not Null
this is what i have. but is not working.
=DCount("[DAYS]","YourTable","[OPER] is Not Null & [days] Between 0
And 30 ")
thanks
=DCount("[DAYS]","YourTable","[OPER] is Not Null and [days] Between 0
And 30 ")

Kris, thanks for the last one, how about this one:

SELECT Count(*)
FROM mydata
WHERE (((mydata.CURRENT) Like "714*") And ((myddata.OPER) Is Not Null)
And ((mydata.DAYS) Between 0 And 10));

=DCount("[CURRENT] like ''714*' ")","myddata","[OPER] is Not Null and
[days] Between 0 And 10 ")

You really need to use MS Help on this stuff - its a much faster way
of getting your answers.

"[CURRENT] like ''714*' " <--What kind of field name is this?

Here: This is the first thing that came up when searching for "DCount"
in Google:
http://www.techonthenet.com/access/functions/domain/dcount.php

Yeah, I could just *fix* your statement, but would that really be
helping you?

-Kris

PS. Don't post the same question in two different places.
 

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