help needed with Nz() and vba coding (1 Viewer)

Misiek

Registered User.
Local time
Today, 21:20
Joined
Sep 10, 2014
Messages
249
ok, changed my mind, going to use a report to display all my Dcounts, based on 2 queries. Any suggestion on how to make it work quickly before I start, please.
 

smig

Registered User.
Local time
Tomorrow, 00:20
Joined
Nov 25, 2009
Messages
2,209
ok, changed my mind, going to use a report to display all my Dcounts, based on 2 queries. Any suggestion on how to make it work quickly before I start, please.
What do you mean by displaying all your DCounts ?
What is based on 2 queries ?
 

Misiek

Registered User.
Local time
Today, 21:20
Joined
Sep 10, 2014
Messages
249
Have 2 queries, but they count different records, just displayed on the same form thats why i said 2 queries, but to begin with I would like to start with the first one, create a report and then go to the second one.
query has:
1. ID
2. date
3. text field A
4.yes/no field
5. text field B(number only)

Count fields on my form, This is what I have now:
1. count how many records
=DCount("qaQAPK","Q_CompStats_qa")
2. how many records where text field A has a value
=DCount("qaQualityIncidentNo","Q_CompStats_qa")
3. how many records where yes/no field has a value = yes
=DCount("qaQAPK","Q_CompStats_qa","qaSeverity=True")

then all of those repeat for each month.
so i just added Month([qaDate]) = 1" criteria.

Does it all look ok? can I just create form with exactly same fields and calculation?
or do you have any suggestions?

thanks
 

smig

Registered User.
Local time
Tomorrow, 00:20
Joined
Nov 25, 2009
Messages
2,209
Each DCount is a query by itself. You have a report with 6 or more queries.
You can create an unbound report, with no data in it, and put these DCounts directly on the report
 

namliam

The Mailman - AWF VIP
Local time
Today, 23:20
Joined
Aug 11, 2003
Messages
11,695
Instead just count it in the query...
Code:
Select Count(qaQAPK) as HowManyRecords
, count(qaQualityIncidentNo) as FieldAhasavalue
, sum(iif(qaSeverity=True),1,0) as SeverityTrue
, sum(iif(qaSeverity=True),0,1) as SeverityFalse
, month(qaDate) as monthofqadate
, year(qadate) as YearOfqaDate
from yourtable
group by 
 month(qaDate)
, year(qadate)
This will be x-1 times faster than doing x dcounts (10 dcounts means 9 times faster, 100 dcounts 99 times faster)
 

Misiek

Registered User.
Local time
Today, 21:20
Joined
Sep 10, 2014
Messages
249
Wooooow I'm already excited, will try it tonight. Thanks for that :)
 

Misiek

Registered User.
Local time
Today, 21:20
Joined
Sep 10, 2014
Messages
249
Namliam,

I'm sorry but just simply don't know.
Where exctly do I need to insert this code?

I'm thinking of text box on event and then create private sub ...
 

namliam

The Mailman - AWF VIP
Local time
Today, 23:20
Joined
Aug 11, 2003
Messages
11,695
it is SQL, you put it into the recordset of the report or into a query
 

Misiek

Registered User.
Local time
Today, 21:20
Joined
Sep 10, 2014
Messages
249
oh I see,
I have created a form and pasted your SQL into the record source, but it comes with an error,

Wrong number of arguments used with function with query expression: "sum(iif(qaSeverity=True),1,0) as SeverityTrue"

unsure of what to do next.
 

Misiek

Registered User.
Local time
Today, 21:20
Joined
Sep 10, 2014
Messages
249
Hello,
I am still stuck on this one.
Can anyone advice on how to create the SQL to make it run faster, please.

Thank you kindly
 

Frothingslosh

Premier Pale Stale Ale
Local time
Today, 17:20
Joined
Oct 17, 2012
Messages
3,276
Your query expression in post 29 is written incorrectly. It should be
Code:
Sum(Iif(qaSeverity=True,1,0)) as SeverityTrue
However, an even better way to do it might be:
Code:
Sum(qaSeverity * (-1)) as SeverityTrue
This is because Access actually saves boolean values as 0 if false and -1 if true. For SeverityFalse, though, you can either try my first code block with "0,1" rather than "1,0", or this:
Code:
Sum(qaSeverity + 1) as SeverityFalse

My latter ways might speed things up a bit by avoiding IIf function calls.
 

namliam

The Mailman - AWF VIP
Local time
Today, 23:20
Joined
Aug 11, 2003
Messages
11,695
I missed your update for some reason, sorry

It seems I misplaced the brackets :(
Code:
Select Count(qaQAPK) as HowManyRecords
, count(qaQualityIncidentNo) as FieldAhasavalue
, sum(iif(qaSeverity=True,1,0)) as SeverityTrue
, sum(iif(qaSeverity=True,0,1)) as SeverityFalse
, month(qaDate) as monthofqadate
, year(qadate) as YearOfqaDate
from yourtable
group by 
 month(qaDate)
, year(qadate)
 

Misiek

Registered User.
Local time
Today, 21:20
Joined
Sep 10, 2014
Messages
249
Frothingslosh & namliam

woooooooow this is sooooo fast and so simple, left me speechless, massive THANK YOU to both of you.

I want your brains :)

I need to create another query, where user selects a department from combo, how to add it to this line:

Code:
, count(qaQualityIncidentNo) as FieldAhasavalue

Thank you
 

Misiek

Registered User.
Local time
Today, 21:20
Joined
Sep 10, 2014
Messages
249
and also,
query shows all data and ordered by month,
how to display data for specific month?

my report looks like this:
------------------jan---- feb---- mar
All QA [value] [value][value][value]
All QI [value] [value][value][value]
severity [value] [value][value][value]
 

Misiek

Registered User.
Local time
Today, 21:20
Joined
Sep 10, 2014
Messages
249
ok googled one of my answers, need to use WHERE
Code:
where qaDeptFK = Forms!F_CompLvl!cboDeptStats

but still unsure what to do with my months, if quewry produces resoults for all months, so to assosiate a text box on the report to show only values (calculation) for specific month.
Can I do it from one query for all months? or do I need 12 separate queries for each month?

Thank you.
 

namliam

The Mailman - AWF VIP
Local time
Today, 23:20
Joined
Aug 11, 2003
Messages
11,695
research a crosstab query, that can do what you want for the months.
 

Misiek

Registered User.
Local time
Today, 21:20
Joined
Sep 10, 2014
Messages
249
thanks namliam,

what am I missing, as it doest show any data in "months"

Code:
TRANSFORM count(T_qa.qaQAPK) AS SumOfQuantity
SELECT Count(T_qa.qaQAPK) AS QAs
FROM Q_ALL_qa
GROUP BY Month(qaDate), Year(qadate)
PIVOT Year([qaDate]*12)
IN (1,2,3,4,5,6,7,8,9,10,11,12);
 

namliam

The Mailman - AWF VIP
Local time
Today, 23:20
Joined
Aug 11, 2003
Messages
11,695
You are doping what? Pivoting the year * 12 and limiting that on 12 months?

Ome limit of accessoires crosstabs is you can only pivot ons column/value so if you want year and month you have to concatenate the something like
Year *100 + month
 

Misiek

Registered User.
Local time
Today, 21:20
Joined
Sep 10, 2014
Messages
249
Silly me.
Ok it's just months now. Fully working :)

Can I combine 2 different fields into one query?
Like I had at the begining, count qaQAPK, qaqualitysomething...
And then show results the same way as I do now?

Is it possible? Or do I need a separate query for each field name I want to have calculations done?
 

namliam

The Mailman - AWF VIP
Local time
Today, 23:20
Joined
Aug 11, 2003
Messages
11,695
You can add as many fields to the ROW HEADING as you want, only 1 column can be COLUMN HEADING

Experiment a bit and see if you like the results or not...

Like I said you can combine the year and the month into one string, the "ugly" part is that columns will be sorted asc and not much you can do about it (without using the hardcoded IN statement).
So in your case you can combine year and month using the formula I already gave you, this should put things in the proper order.
 

Users who are viewing this thread

Top Bottom