Results 1 to 5 of 5
  1. #1
    tomnsd is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    17

    NetworkingDays

    I have a function to return the networking days. It seems to work fine, except if there is a date missing it returns a #error. I would like it just to leave the cell blank. Can someone help?


    Code:
    Option Compare Database
    
    Option Explicit
    
    
    Public Function Workdays(dteStart As Date, dteEnd As Date) As Long
        Dim lngDate As Long
        Dim rst As DAO.Recordset
        Dim dbs As DAO.Database
            
         If IsNull(dteStart) Or IsNull(dteEnd) Then
         GoTo Exitpoint
         End If
         
         Set dbs = CurrentDb
         Set rst = dbs.OpenRecordset("Holidays", dbOpenSnapshot)
         
       ' NetWorkdays = -1
        ' Check for valid dates.
        If IsDate(dteStart) And IsDate(dteEnd) Then
            ' Strip off any fractional days and just use whole days.
            For lngDate = Int(dteStart) To Int(dteEnd)
            
                If Weekday(lngDate, vbMonday) < 6 Then
                       rst.FindFirst "[Holiday] = #" & Format(lngDate, "mm\/dd\/yyyy") & "#"
                       If rst.NoMatch Then
                       Workdays = Workdays + 1
                       End If
                  
                End If
            Next lngDate
        End If
      rst.Close
      Set rst = Nothing
      Set dbs = Nothing
    
    
    Exitpoint:
       
        Exit Function
    
    
    End Function

  2. #2
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,914
    Are you calling function in a query?

    Show the expression that calls the function.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    tomnsd is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    17
    Yes. Workdays(3/12/2013,3/15/2013)

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,914
    If you are calling in a query I presume there are actually field names where you show date values in that expression. I was looking for your field names but I will use mine instead. Try:

    IIf(IsNull(StartDate) Or IsNull(EndDate), Null, Workdays(Nz(StartDate,#1/1/2000#),Nz(EndDate,#1/1/2000#)))
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    tomnsd is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Jan 2013
    Posts
    17
    Thank you.

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

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