Page 1 of 2 12 LastLast
Results 1 to 15 of 22
  1. #1
    Harry is offline Novice
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Oct 2010
    Location
    library
    Posts
    2

    codes for working days error

    can someone see anything wrong with this :

    Public Function NextWorkDay(dtmDate As Date) As Date
    '****************************************
    'Created By: Robert L. Johnson III
    'Mod Date: February 19, 2003
    'Purpose: Determine the next business (working) day
    'In: dteDate is the date to be checked
    'Out: Returns the next business day
    'Example: NextWorkDay(#12/31/02#) returns 1/2/03
    ' (1/1/01 is a holiday (New Year's Day))
    '****************************************
    Dim dtmTemp As Date
    Dim blnNextWorkday As Boolean

    dtmTemp = dtmDate + 1
    blnNextWorkday = False
    Do Until blnNextWorkday = True
    If IsWeekend(dtmTemp) = True Or IsHoliday(dtmTemp) = True Then
    dtmTemp = DateAdd("d", 1, dtmTemp)
    Else
    blnNextWorkday = True
    End If
    Loop
    NextWorkDay = dtmTemp



    or have any codes to work out next work day

  2. #2
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    Your code looks good!
    But it took a while for me to understand it. Following code maybe easier to understand?

    Code:
    Public Function NextWorkDay(dtmDate As Date) As Date
    'Purpose: Determine the next business (working) day
    'In: dteDate is the date to be checked
    'Out: Returns the next business day
    'Example: NextWorkDay(#12/31/02#) returns 1/2/03
    ' (1/1/01 is a holiday (New Year's Day))
    '****************************************
        nextworkday = dtmDate + 1
        Do While IsWeekend(nextworkday) Or IsHoliday(nextworkday)
            nextworkday = nextworkday + 1
        Loop
    end function

  3. #3
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    What you posted is missing at least an End Function statement and two additional functions used along with a Dim statement that should not be there. "Dim dtmTemp As Date" This variable is already defined in the 1st line.

  4. #4
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    There are at least three post about this code. It looks like all of you are taking the same class.

  5. #5
    Rawb is offline Expert
    Windows XP Access 2000
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    Quote Originally Posted by RuralGuy View Post
    There are at least three post about this code. It looks like all of you are taking the same class.
    rofl!

    I agree that it's missing Code for those two other Functions (IsWeekday and IsHoliday), but I don't see where he's double-Dimming any variables.

    As for what's wrong with the code, do you have the specific error message or number? That could help us figure out the problem. If you're getting a compile error, then I'd go with the missing "End Function". If it's a runtime error, then it's something else.

    EDIT: Whoops! You are double Dimming! You've Dimmed dtmDate as a passed argument as well as down below (so RG's right all around!). That's most likely where your error is.

  6. #6
    TheShabz is offline Court Jester
    Windows XP Access 2003
    Join Date
    Feb 2010
    Posts
    1,368
    Also, I'd always throw in "Option Explicit" just to make sure you have all your variables properly declared.

  7. #7
    slave138's Avatar
    slave138 is offline Competent Performer
    Windows XP Access 2007
    Join Date
    Oct 2010
    Location
    WI
    Posts
    233
    Quote Originally Posted by Rawb View Post
    I agree that it's missing Code for those two other Functions (IsWeekday and IsHoliday), but I don't see where he's double-Dimming any variables.
    ...
    EDIT: Whoops! You are double Dimming! You've Dimmed dtmDate as a passed argument as well as down below (so RG's right all around!). That's most likely where your error is.

    I think you were right the first time. There is a Dim dtmTemp declared in the function but I only see dtmDate declared as a function parameter.

  8. #8
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    Quote Originally Posted by slave138 View Post
    I think you were right the first time. There is a Dim dtmTemp declared in the function but I only see dtmDate declared as a function parameter.
    Okay, I was in error so thanks for the perspective! It has not been double Dimmed. It is also an unnecessary variable since the code could have used the dtmDate variable throughout. It looks like the code would work to me but I didn't try it.

  9. #9
    weekend00 is offline I may not be right
    Windows XP Access 2003
    Join Date
    Aug 2010
    Posts
    1,295
    The owner of the post is gone while we are argueing here

  10. #10
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    I think the class they are all taking is "How to drive Forum helpers nuts!".

  11. #11
    Rawb is offline Expert
    Windows XP Access 2000
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    Yeah, I'm pretty sure he just grabbed weekend's code and ran off with it.

    I'm curious though. . .

    Since I was wrong about being wrong was I right? Or was I wrong for being wrong about being wrong and therefore being right?

  12. #12
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    That's right! You were wrong about being wrong!

  13. #13
    ajetrumpet is offline VIP
    Windows Vista Access 2007
    Join Date
    Mar 2010
    Location
    N/A
    Posts
    2,694
    Quote Originally Posted by RuralGuy View Post
    I think the class they are all taking is "How to drive Forum helpers nuts!".
    It would be worse if this was real life. =)

  14. #14
    Rawb is offline Expert
    Windows XP Access 2000
    Join Date
    Dec 2009
    Location
    Somewhere
    Posts
    875
    Wait. . .

    So we're all just in an Inception-like dream??!?

  15. #15
    RuralGuy's Avatar
    RuralGuy is offline Administrator
    Windows 7 Access 2010 (version 14.0)
    Join Date
    Mar 2007
    Location
    8300' in the Colorado Rocky Mountains
    Posts
    12,922
    You catch of quickly! 8^)

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Finding subsequent codes
    By Rixxe in forum Queries
    Replies: 8
    Last Post: 09-15-2010, 02:44 AM
  2. Select Dates between days and two days ago?
    By rstonehouse in forum Queries
    Replies: 4
    Last Post: 08-18-2010, 02:13 AM
  3. combobox.dropdown event not working after error
    By perlyman in forum Programming
    Replies: 1
    Last Post: 04-02-2010, 06:55 PM
  4. calculate no. of working days
    By JOSE LUIS in forum Access
    Replies: 1
    Last Post: 02-01-2010, 03:55 PM
  5. basic query codes
    By joms222 in forum Queries
    Replies: 1
    Last Post: 03-20-2009, 11:31 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