Get a Function call from a query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • leucine
    New Member
    • Oct 2006
    • 6

    Get a Function call from a query

    I have a function wrote in a module that will return fiscal month of our calendar as following.

    Function getDueMonth(Due Date As Date)

    Dim DueMonth As Integer
    Set fd = New clsFiscalDate
    fd.SetDate = DueDate
    DueMonth = fd.MonthNumber
    'Debug.Print DueMonth
    End Function

    The print value is correct by using Debug.

    I want to use this function in one of my queries but it seems it is not correctly called. No record shows using this query although some records exist. Could anyone give me hints to do this.

    My query is as following
    "SELECT Grade.studentNa me, Grade.score FROM Grade WHERE Grade.dueMonth = getDueMonth(Now ());
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    Originally posted by leucine
    I have a function wrote in a module that will return fiscal month of our calendar as following.

    Function getDueMonth(Due Date As Date)

    Dim DueMonth As Integer
    Set fd = New clsFiscalDate
    fd.SetDate = DueDate
    DueMonth = fd.MonthNumber
    'Debug.Print DueMonth
    End Function

    The print value is correct by using Debug.

    I want to use this function in one of my queries but it seems it is not correctly called. No record shows using this query although some records exist. Could anyone give me hints to do this.

    My query is as following
    "SELECT Grade.studentNa me, Grade.score FROM Grade WHERE Grade.dueMonth = getDueMonth(Now ());
    Hi. You have not set a return type or value for your function:
    Code:
    Function getDueMonth(DueDate As Date) [B]As Integer[/B]
    
        Dim DueMonth As Integer
        Set fd = New clsFiscalDate
        fd.SetDate = DueDate
        DueMonth = fd.MonthNumber
    'Debug.Print DueMonth
       [B]getDueMonth = DueMonth[/B]
    End Function

    Comment

    • leucine
      New Member
      • Oct 2006
      • 6

      #3
      Originally posted by willakawill
      Hi. You have not set a return type or value for your function:
      Code:
      Function getDueMonth(DueDate As Date) [B]As Integer[/B]
      
          Dim DueMonth As Integer
          Set fd = New clsFiscalDate
          fd.SetDate = DueDate
          DueMonth = fd.MonthNumber
      'Debug.Print DueMonth
         [B]getDueMonth = DueMonth[/B]
      End Function
      Thank you very much. I know how to write a function to return a value now.

      Comment

      • willakawill
        Top Contributor
        • Oct 2006
        • 1646

        #4
        Originally posted by leucine
        Thank you very much. I know how to write a function to return a value now.
        You are very welcome

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32634

          #5
          Leucine,
          I strongly recommend that you declare ALL the variables you use.
          Not doing so will lead you into hard to find errors.
          In the VBA window select Tools / Options and check 'Require Variable Declaration' on the Editor tab.
          This will then insist that all variables you use are defined first. This has so many benefits! It is only not mandatory because M$ want to encourage all types of newbies to be able to start using VBA. The problems it causes are not M$'s responsibility it seems...

          Comment

          Working...