Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Queries / February 2008

Tip: Looking for answers? Try searching our database.

Expression typed incorrectly or too complex?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
FBxiii - 21 Feb 2008 10:31 GMT
I have a query that uses a function to calculate the number of working days
between 2 dates.  The query works fine and returns the number of days.

I am using the query to get a count of records 'cleared' in over 10 days.  
When I put a criteria under the calculated field to determine any records
over 10 days, I get an error saying "The expression is typed incorrectly or
is too complex to be evaluated".

Here is the SQL:
SELECT zREP_SAR_Files_Received_by_Date.Submitting_SSC,
Count(tblSAR_Tracker.MPR) AS CountOfMPR
FROM zREP_SAR_Files_Received_by_Date INNER JOIN tblSAR_Tracker ON
zREP_SAR_Files_Received_by_Date.File_Name = tblSAR_Tracker.File_Name
WHERE (((calculate_working_days([Received_Date],[Cleared_Date]))>10))
GROUP BY zREP_SAR_Files_Received_by_Date.Submitting_SSC;

Can anyone see what I am doing wrong?

Cheers,
Steve.
Allen Browne - 21 Feb 2008 12:01 GMT
This is a very general message that just means JET got stuck somewhere.

One cause is where the data types don't match. We don't know how your
calculate_working_days() function is declared: what type of arguments does
it take, and what type does it return? Does it accept variants, and return a
variant? What happens if either of the aguments passed in is null? Is there
a chance that JET could understand it as a non-numeric value, and therefore
be unable to evaluate it against a numeric value (i.e. 10)?

Signature

Allen Browne - Microsoft MVP.  Perth, Western Australia
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

>I have a query that uses a function to calculate the number of working days
> between 2 dates.  The query works fine and returns the number of days.
[quoted text clipped - 17 lines]
> Cheers,
> Steve.
John Spencer - 21 Feb 2008 13:24 GMT
My G_U_E_S_S is that Calculate_Working_Days is returning an error on one
or more of the records.  Probably because you are passing it a null
value in one or more of its arguments and not handling that possibility
in the function.

You might consider posting the function for review.

'====================================================
 John Spencer
 Access MVP 2002-2005, 2007-2008
 Center for Health Program Development and Management
 University of Maryland Baltimore County
'====================================================

> This is a very general message that just means JET got stuck somewhere.
>
[quoted text clipped - 5 lines]
> value, and therefore be unable to evaluate it against a numeric value
> (i.e. 10)?
FBxiii - 21 Feb 2008 14:17 GMT
Thanks for the replies.

The query works when I do not supply a criteria for the
calculate_working_days field.  I have checked for Null values in the date
fields and there doesnt seem to be any.  I have also tried changing the data
type being passed back from the function from Integer to Variant and Long.

I have used this function in the same way in the past and it normally works!!

The function is as follows:

Public Function Calculate_Working_Days(StartDate As Date, EndDate As Date)
As Integer

'--------------------------------------------------
'Calculates the correct amount of working days
'between two dates including bank holidays. Bank
'holidays are contained in the table zSYS_tblSpecialDays
'--------------------------------------------------

Dim dayCount As Integer
Dim wkendCount As Long '---- No of weekend days to be subtracted ----
Dim intDiff As Long  '---- Number of all days between 2 dates ----
Dim dbldiff As Double
Dim finaldiff As Long   '---- Final figure
Dim rstDays As Recordset
Dim SpecCount As Integer '---- Number of special days between the two dates
----
Dim DateRet1 As Date '---- Same date as Date2 ----
Dim date1 As Date
Dim date2 As Date
Dim nulldate As Integer

'Dim db As database

Set db = CurrentDb()
Set rstDays = db.OpenRecordset("zSYS_tblSpecialDays")
 
Dim rec As Long

DateRet1 = Format(DateRet1, "dd/mm/yyyy")
StartDate = Format(StartDate, "dd/mm/yyyy")

rec = rec + 1

   If StartDate <> Empty And EndDate <> Empty Then
       
       If StartDate < EndDate Then
       
           date1 = StartDate
           date2 = EndDate
           
       Else
           date1 = EndDate
           date2 = StartDate
       End If
           
   Else
       nulldate = 1
   End If
   
       
   If nulldate = 0 Then
   
       intDiff = date2 - date1
       
       wkendCount = 0
       SpecCount = 0
       
       Do Until date2 = date1
           
           dayCount = WeekDay(date2)
           
           If dayCount = 1 Or dayCount = 7 Then
               wkendCount = wkendCount + 1
           End If
           
       '---- Calculates amount of bank holidays between dates ----
       ' Uses daycount and checks Fridays, Mondays and Tuesdays
       
           If dayCount = 2 Or dayCount = 3 Or dayCount = 6 Then
           
               rstDays.MoveFirst
                         
               Do Until rstDays.EOF
                   If rstDays![Date] = date2 Then
                       SpecCount = SpecCount + 1
                   End If
                   
                   rstDays.MoveNext
               
               Loop
                   
               rstDays.MoveFirst
               
           End If
               
           date2 = date2 - 1
                             
         '  Debug.Print date1, date2, daycount, wkendCount, SpecCount
                           
       Loop
       
               
       '---- Final total of working days ----
                     
       If StartDate < EndDate Then
          finaldiff = intDiff - (wkendCount + SpecCount)
       Else
           dbldiff = 2 * (intDiff - (wkendCount + SpecCount))
           finaldiff = intDiff - (wkendCount + SpecCount) - dbldiff
       End If
             
   End If
       
   Calculate_Working_Days = finaldiff
   
   nulldate = 0

End Function

> My G_U_E_S_S is that Calculate_Working_Days is returning an error on one
> or more of the records.  Probably because you are passing it a null
[quoted text clipped - 19 lines]
> > value, and therefore be unable to evaluate it against a numeric value
> > (i.e. 10)?
FBxiii - 25 Feb 2008 15:51 GMT
I think im going to have to create a function to process this report.  I have
found if I create a table containing the number of days to clear, it stops
this error.

I would of liked to do it one foul swoop but time is running out.

Heres to the long way round :)

Thanks anyway,
Steve.

> Thanks for the replies.
>
[quoted text clipped - 140 lines]
> > > value, and therefore be unable to evaluate it against a numeric value
> > > (i.e. 10)?
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.