Results 1 to 8 of 8

Thread: Where's the error?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2002
    Posts
    195

    Where's the error?

    Is there anything wrong with this function? Whenever I call it, I get an error saying "Wrong number of arguments or invalid property assignment" with the Day function highlighted...

    Code:
    Private Function DaysInMonth(iMonth As Long, iYear As Long) As Integer
    
        DaysInMonth = Day(DateSerial(iYear, iMonth + 1, 0))
    
    End Function
    ... it looks okay to me. This is code running under VBA in MS Access if that makes a difference.
    Using Visual Studio .NET 2005

  2. #2
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: Where's the error?

    Here's my version of this function.

    VB Code:
    1. Function DaysInMonth(MthNum As Integer, YrNum As Integer) As Integer
    2. Dim dtTemp As Date
    3.    
    4.     dtTemp = DateSerial(YrNum, MthNum, 1)
    5.     DaysInMonth = DateAdd("M", 1, dtTemp) - dtTemp
    6. End Function
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

  3. #3
    Superbly Moderated NeedSomeAnswers's Avatar
    Join Date
    Jun 2002
    Location
    Manchester uk
    Posts
    2,657

    Re: Where's the error?

    Works Fine when i run it !!, what version of Access are you using ?

    I don't see any reason why this shouldn't work to be honest !

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Where's the error?

    Worked just fine for me as well.

  5. #5
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: Where's the error?

    Do you have the reference set to use Day()? What's the error?
    Tengo mas preguntas que contestas

  6. #6

    Thread Starter
    Addicted Member
    Join Date
    Nov 2002
    Posts
    195

    Re: Where's the error?

    Quote Originally Posted by salvelinus
    Do you have the reference set to use Day()? What's the error?
    Erm... maybe. How can I check for that? I replaced the function with DKenny's version and that seems to work. I'm pretty sure I had used the Day function before though, and it worked then...
    Using Visual Studio .NET 2005

  7. #7
    Frenzied Member
    Join Date
    Feb 2003
    Location
    Argentina
    Posts
    1,950

    Re: Where's the error?

    In the VBE, Tools-References and check Microsoft DAO 3.6 Object Library (at least I think that's the correct one, according to the Object Browser)
    Tengo mas preguntas que contestas

  8. #8

    Thread Starter
    Addicted Member
    Join Date
    Nov 2002
    Posts
    195

    Re: Where's the error?

    Yeah, it's selected so I'm not sure the problem is.

    This isn't related (or at least I don't think so) but I doubt it's worth creating a new topic for. Apparently the Range object (used for a spreadsheet control) has a resize function...
    Code:
    'Get the range of the current table
    Dim tableRange As Range
    Set tableRange = Sheet.Cells(1, 1)
     
    Set tableRange = tableRange.Resize(m_dimX, m_dimY)
    .. however, whenever I run that I get 'Method or data member not found'. I figured I might as well post it here since, again, it seems to be VBA not finding something it should (whether it be a function or a method).

    This isn't going well at all...
    Using Visual Studio .NET 2005

Posting Permissions

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



Click Here to Expand Forum to Full Width