Results 1 to 4 of 4
  1. #1
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,085

    Query datediff error

    I have a Microsoft access 2010 Query that calls the below function. The function works fine when dtdisch is populated however when it is null the query shows #Error. The Errhandler in the function does not execute What am I missing? I've replaced the IsNull(dtdisch) to IsDate(dtdisch) but got the same result.

    Public Function LOS(ByRef dtadmit As Date, dtdisch As Date) As Long
    Dim tmpdt As Date
    On Error GoTo errhandler
    If IsNull(dtdisch) Then


    tmpdt = Date
    Else
    tmpdt = dtdisch
    End If
    LOS = DateDiff("d", dtadmit, tmpdt)
    If LOS = 0 Then LOS = 1
    ExitHandler:
    Exit Function
    errhandler:
    MsgBox Err.Description, vbOKOnly, "Error"
    Resume ExitHandler
    End Function

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    This

    dtdisch As Date

    needs to be

    dtdisch As Variant

    The Date data type can't accept a Null.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,085
    Doh, I knew it was something simple I was overlooking. Thanks.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,641
    No problemo.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

Please reply to this thread with any new information or opinions.

Similar Threads

  1. DateDiff Missing Operator? Long Query
    By ewassmer in forum Queries
    Replies: 1
    Last Post: 08-25-2011, 10:46 AM
  2. DateDiff
    By mrkaye in forum Forms
    Replies: 18
    Last Post: 11-19-2010, 08:19 AM
  3. DateDiff
    By ROB in forum Access
    Replies: 2
    Last Post: 10-30-2010, 03:58 AM
  4. Need Help with Datediff
    By gonzod in forum Access
    Replies: 5
    Last Post: 08-26-2010, 02:29 PM
  5. Query DateDiff calculation excluding weekends
    By Masterfinn in forum Queries
    Replies: 3
    Last Post: 04-01-2010, 09:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums