Results 1 to 5 of 5
  1. #1
    vickan240sx is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    May 2012
    Posts
    34

    can anybody help me find out why it's saying I have no "Do" with my "Loop"?

    Code:
    Public Function WorkingDays(StartDate As Date, EndDate As Date) As Integer
    '-- Return the number of WorkingDays between StartDate and EndDate
    On Error GoTo err_workingDays
    
    Dim intCount As Integer
    
    If IsDate(StartDate) And IsDate(EndDate) Then
       If EndDate >= StartDate Then
    
          intCount = 0
          Do While StartDate < EndDate
             StartDate = StartDate + 1
             If Weekday(StartDate, vbMonday) <= 5 Then
          '-- Use the following code if you have a "Holiday" table
             If Weekday(StartDate, vbMonday) <= 5 And _
                IsNull(DLookup("[Holiday]", "Holidays", _
                "[HolDate] = " & Format(StartDate, "\#mm\/dd\/yyyy\#;;;\N\u\l\l"))) Then
    
                intCount = intCount + 1
             End If
          Loop
          WorkingDays = intCount
       Else
          WorkingDays = -1  '-- To show an error
       End If
    Else
       WorkingDays = -1  '-- To show an error
    End If
    
    exit_workingDays:
       Exit Function
    
    err_workingDays:
       MsgBox "Error No:    " & Err.Number & vbCr & _
       "Description: " & Err.Description
       Resume exit_workingDays
    
    End Function
    Thank you for your help.

  2. #2
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You are missing an "End If" that throws off the "LOOP" .
    Code:
    Public Function WorkingDays(StartDate As Date, EndDate As Date) As Integer
    '-- Return the number of WorkingDays between StartDate and EndDate
       On Error GoTo err_workingDays
    
       Dim intCount As Integer
    
       If IsDate(StartDate) And IsDate(EndDate) Then
          If EndDate >= StartDate Then
    
             intCount = 0
             Do While StartDate < EndDate
                StartDate = StartDate + 1
                If Weekday(StartDate, vbMonday) <= 5 Then
                   '-- Use the following code if you have a "Holiday" table
                   If Weekday(StartDate, vbMonday) <= 5 And _
                      IsNull(DLookup("[Holiday]", "Holidays", _
                                     "[HolDate] = " & Format(StartDate, "\#mm\/dd\/yyyy\#;;;\N\u\l\l"))) Then
    
                      intCount = intCount + 1
                   End If
                End If   ' <<-- add this
             Loop
             WorkingDays = intCount
          Else
             WorkingDays = -1  '-- To show an error
          End If
       Else
          WorkingDays = -1  '-- To show an error
       End If
    
    exit_workingDays:
       Exit Function
    
    err_workingDays:
       MsgBox "Error No:    " & Err.Number & vbCr & _
              "Description: " & Err.Description
       Resume exit_workingDays
    
    End Function

  3. #3
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,071
    Yep- You have 2 If statements but only 1 End if.

  4. #4
    RayMilhon is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,071
    ssanfu- you beat by by a couple of seconds.

  5. #5
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    But I had to start sooner......

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

Similar Threads

  1. Replies: 3
    Last Post: 06-29-2012, 08:54 AM
  2. Replies: 11
    Last Post: 03-29-2012, 02:32 PM
  3. Replies: 8
    Last Post: 08-05-2011, 02:55 PM
  4. Replies: 16
    Last Post: 07-22-2011, 09:23 AM
  5. "Group By" causes "ODBC--Call Failed" error
    By kaledev in forum Queries
    Replies: 1
    Last Post: 03-09-2011, 02:43 PM

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