Subquery for calculated field - probs with crosstab

Tech-Archive recommends: Fix windows errors by optimizing your registry



Hi

I have a query which calculates the number of working days between two
dates, [ReqDate] (the earlier date) and [RepDate]. The SQL uses the
following DateDiff/IIf construction, I believe due to Doug Steele, which
works fine:

PARAMETERS [Forms]![frmTurnaroundAll]![txtBeginDate] DateTime,
[Forms]![frmTurnaroundAll]![txtEndDate] DateTime,
[Forms]![frmTurnaroundAll]![cboCaseType] Text ( 255 );
SELECT tblCases.CaseNo, tblCases.ReqDate, tblCases.RepDate,
IIf(IsNull([VerPathologist]),"UNKNOWN",[VerPathologist]) AS Pathologist,
1+DateDiff("d",[ReqDate],[RepDate])-DateDiff("ww",[ReqDate],[RepDate])*2-IIf(Weekday([RepDate],1)=7,IIf(Weekday([ReqDate],1)=7,0,1),IIf(Weekday([ReqDate],1)=7,-1,0))
AS WorkDayTurnaround
FROM tblCases
WHERE (((tblCases.CaseNo) Like Forms!frmTurnaroundAll!cboCaseType & "*") And
((tblCases.ReqDate) Between Forms!frmTurnaroundAll!txtBeginDate And
Forms!frmTurnaroundAll!txtEndDate))
ORDER BY tblCases.CaseNo;

Case No is the primary key in tblCases and is a text field. I add 1 at the
beginning of the calculation to make it inclusive of the beginning and end
date. I also would like to exclude public holidays, so I have a table,
tblHolidays, with a field HolidayDate such that if I construct the subquery

SELECT Count(*) AS HolidayCount FROM tblHolidays WHERE
(((tblHolidays.HolidayDate) Between tblCases.ReqDate And tblCases.RepDate))

and subtract it from the main expression, it works fine in this query but
not in any crosstab based on it. Is there any way round this or do I have to
use VBA?

Tony


.



Relevant Pages

  • Re: User defined type not defined error
    ... it gives me the following Microsoft error: ... > query 'tblHolidays'. ... You say you created a table named "Holidays", but the code you posted is ... looking for a table named "tblHolidays". ...
    (microsoft.public.access.modulesdaovba)
  • RE: Networking days, weekends, holidays and delivery days cancelle
    ... I was able to get the module to work, but when I try to query the results, I ... It excludes Saturdays, Sundays, and any date with an entry in the Holidays ... Dim dtmDate As Date ... On Error GoTo CountWeekDays_Error ...
    (microsoft.public.access.queries)
  • Re: Create Weekly and Monthly Flag in database/table
    ... WHERE field1 In; ... the weekday(datefield [,optional first day of week)) returns a ... In the query designer if you put your field2, ... small table with the holidays that fall on a friday. ...
    (comp.databases.ms-access)
  • RE: DateFunction in Query
    ... I'm all of a sudden getting this error when I open the query, ... Undefined function 'CalcWorkDays' in expression ... dtmEnd As Date) As Integer ... 'Subtract the Holidays ...
    (microsoft.public.access.queries)
  • Re: Autofill every possible record
    ... have it recognize around 12 holidays from the holiday table and omit these ... Combining them in a query without joins (a ... Save the table as tblDate. ... Change the query to an Append query ...
    (microsoft.public.access.queries)