looping through days in a table (1 Viewer)

MICHELE

Registered User.
Local time
Today, 05:45
Joined
Jul 6, 2000
Messages
117
Hi
I have this module that Mile-O-Phile helped me with and it works great. I have made a couple of changes so that it not only skips over Sundays, but should skip over drivingHolidays. It's doesn't seem to be recognizing driving holidays. stringDriving field should be changing as dteTemp1 changes and it doesn't seem to be changing when it goes through the loop. Can anyone see what my problem with this code?
Thank you in advance for any help!


Code:
Public Function NoDrivingHolidays(dteTemp1 As Date, dteTemp2 As Date, strDriving As String, intDays As Integer) As Date
    On Error GoTo Err_NoDrivingHolidays
    strDriving = "NO"
    Do While Not intDays = 0
        dteTemp1 = DateAdd("d", -1, dteTemp1)
        If (Not WEEKDAY(dteTemp1) = 1) And strDriving = "No" Then
            intDays = intDays - 1
        End If
    Loop
    NoDrivingHolidays = dteTemp1
Exit_NoDrivingHolidays:
    Exit Function
Err_NoDrivingHolidays:
    MsgBox Err.DESCRIPTION, vbExclamation, "Error #" & Err.NUMBER
    Resume Exit_NoDrivingHolidays
End Function
 
Last edited by a moderator:

Mile-O

Back once again...
Local time
Today, 05:45
Joined
Dec 10, 2002
Messages
11,316
Why have you passed a value called strDriving and then immediately changed it so that it remains as "NO" throughout the duration of the code's execution?

You say it should be changing; to what?
 

MICHELE

Registered User.
Local time
Today, 05:45
Joined
Jul 6, 2000
Messages
117
Mile-O-Phile said:
Why have you passed a value called strDriving and then immediately changed it so that it remains as "NO" throughout the duration of the code's execution?

You say it should be changing; to what?


Sorry, I forgot to take that out.

strDriving was a boolean but now it's a string that defaults to "NO" and changes to "YES" when the date in my holiday table = [DELIVERYDATE] which is dteTemp1
 

Mile-O

Back once again...
Local time
Today, 05:45
Joined
Dec 10, 2002
Messages
11,316
But you've completely lost me as this line:

Code:
Public Function NoDrivingHolidays(dteTemp1 As Date, dteTemp2 As Date, _
    strDriving As String, intDays As Integer) As Date

...as you are passing in a value which is assumed by strDriving.
And then you change whatever that value is to "NO" :confused:

If it's not a necessary value from the source then I'd suggest omitting it from the parameters and dimensioning it within the function. The same goes for dteTemp2 which you haven't used at all.

Code:
Public Function NoDrivingHolidays(dteTemp1 As Date, intDays As Integer) As Date
    On Error GoTo Err_NoDrivingHolidays
    Dim strDriving As String
    strDriving = "NO"

The only thing you are missing is the code to look up your holiday table; that's why it's continually set to "NO"
 

Users who are viewing this thread

Top Bottom