Limiting calculated query (1 Viewer)

akuller

New member
Local time
Today, 09:14
Joined
Aug 2, 2010
Messages
3
Hi, I'm sure this is simple, but I am very new to access. I have a query which contains activity types, example, "Holiday", "Free", "Blocked" etc. Each of these fields has both a start and end date associated with it. In addition I built a simple calculated field which counts the number of days between start and end date for each activity type. I would like to NOT show the number of days on certain field types, such as "Blocked" and "Holiday". I am having difficulty doing this. Can someone help?

Thanks!
 

PNGBill

Win10 Office Pro 2016
Local time
Tomorrow, 04:14
Joined
Jul 15, 2008
Messages
2,271
Hi, I'm sure this is simple, but I am very new to access. I have a query which contains activity types, example, "Holiday", "Free", "Blocked" etc. Each of these fields has both a start and end date associated with it. In addition I built a simple calculated field which counts the number of days between start and end date for each activity type. I would like to NOT show the number of days on certain field types, such as "Blocked" and "Holiday". I am having difficulty doing this. Can someone help?

Thanks!
You could use IIF in your Calculated Field but you may be limited in the values you return. eg, you are working with Dates and I guess you use Date Diff. Then how do you get Null to be a Date value?

Also, consider where you use the result ie A Form. You could have VBA make the control Invisible if some other field was a certain value - again may not be that simple if you use a continuous form.

This response doesn't resolve your question but may assist you in getting a little further along.
 

vbaInet

AWF VIP
Local time
Today, 17:14
Joined
Jan 22, 2010
Messages
26,374
Follow up to PNGBill's advice, you would test that both dates are valid dates, and by this it would automatically take into account Nulls. You do this by using the IsDate() function.

So you test both fields, if they are not valid dates return Null else perform the DateDiff() calculation. My advice would be to have two alias fields, one to perform the above-mentioned DateDiff() calculation and the other to hide the value of the calculation if it's Blocked or holiday.

Some skeleton code:
Code:
FirstAlias: IIF(IsDate([Date1]) And IsDate([Date2]), DateDiff(...), Null)
Code:
SecondAlias: IIf([ActivityType]="Blocked" Or [ActivityType]="Holiday", Null, [FirstAlias])
 

akuller

New member
Local time
Today, 09:14
Joined
Aug 2, 2010
Messages
3
I can try that...but not too saavy. I was able to Not show the fields if they were Blocked etc..so that eliminated the need to hid the # of days. I just thought there might be an easy way to do that.

Thanks!
 

vbaInet

AWF VIP
Local time
Today, 17:14
Joined
Jan 22, 2010
Messages
26,374
If you still can't figure it out just drop a quick message and we will advise.
 

Users who are viewing this thread

Top Bottom