Results 1 to 6 of 6
  1. #1
    2 Star Lounger
    Join Date
    May 2001
    Location
    Maryland, USA
    Posts
    105
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Previous Monday (2003)

    I am setting up some fields on a form to calculate an expiration date. The first step in the process is to return the Monday of the week of the production date. I have this function:

    Option Compare Database

    Function GetLastMonday(ByVal dtIn)
    Dim i, dtTestDate
    For i = 0 To 7
    dtTestDate = DateAdd("d", -i, dtIn)
    If Weekday(dtTestDate) = 2 Then
    GetLastMonday = dtTestDate
    Exit Function
    End If
    Next
    End Function

    I have two text boxes: “Production” to enter the production date and the other “ZeroDate” with this expression: =GetLastMonday([Production]). But when I type the expression in and hit enter I get the “The object doesn’t contain the Automation object ‘GetLastMonday.’ message.

    I’m not sure what I’m doing wrong. Any help would be appreciated.

    Thanks,
    Eric

  2. Get our unique weekly Newsletter with tips and techniques, how to's and critical updates on Windows 7, Windows 8, Windows XP, Firefox, Internet Explorer, Google, etc. Join our 480,000 subscribers!

    Excel 2013: The Missing Manual

    + Get this BONUS — free!

    Get the most of Excel! Learn about new features, basics of creating a new spreadsheet and using the infamous Ribbon in the first chapter of Excel 2013: The Missing Manual - Subscribe and download Chapter 1 for free!

  3. #2
    Gold Lounger
    Join Date
    Jun 2001
    Location
    Crystal Beach, FL, Florida, USA
    Posts
    3,326
    Thanks
    1
    Thanked 12 Times in 12 Posts

    Re: Previous Monday (2003)

    Where did you declare the function? In that form or a module? If a module, try putting PUBLIC before it.
    Mark Liquorman
    See my website for Tips & Downloads and for my Liquorman Utilities.

  4. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: Previous Monday (2003)

    Where did you create the function?

  5. #4
    2 Star Lounger
    Join Date
    May 2001
    Location
    Maryland, USA
    Posts
    105
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Previous Monday (2003)

    It's in a module. I put PUBLIC before it. Still doesn't want to do anything. The ZeroDate field just sits there with #Name? in it.

    Option Compare Database

    Public Function GetLastMonday(ByVal dtIn)
    Dim i, dtTestDate
    For i = 0 To 7
    dtTestDate = DateAdd("d", -i, dtIn)
    If Weekday(dtTestDate) = 2 Then
    GetLastMonday = dtTestDate
    Exit Function
    End If
    Next
    End Function

  6. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 16 Times in 16 Posts

    Re: Previous Monday (2003)

    Did you name the module GetLastMonday too? That would cause the #Name error because it confuses Access. If you did, rename the module, for example to basLastMonday.

  7. #6
    2 Star Lounger
    Join Date
    May 2001
    Location
    Maryland, USA
    Posts
    105
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Previous Monday (2003)

    Great! That did it. Works now. Thank you.

    Eric

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •