Unable to open function inside a method

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jriechers
    New Member
    • Mar 2008
    • 11

    Unable to open function inside a method

    The following is a quick example of what I am trying to do:

    ---
    Private Sub MonthCombo_Afte rUpdate(Cancel As Integer)

    [test] = First_Saturday( )

    End Sub
    ---

    Basically when the user changes the month in the form header it will update all the patch windows using their particular function.

    MonthCombo is a control box in a form

    [test] is a textbox in a form

    First_Saturday( ) is a function in a module named DateCalculation .

    Originally I had attached each function directly to related textbox as default value which worked just fine until I figured it need the flexibility of changing the month value.

    I had changed a function to replace Month(Date) with [Form]![test]![MonthCombo] which works, but only as the form loads. I need the data to update if the month is changed.

    This is the following error I get as the AfterUpdate runs...

    The expression After Update you entered as the event property setting produced the following error: Procedure declaration does not match description of event or procedure having the same name.
  • missinglinq
    Recognized Expert Specialist
    • Nov 2006
    • 3533

    #2
    We really need to see the code for First_Saturday( ) in order to help, I think. My guess woud be that if it worked for the current month, when you had it set as a default value, but doesn't work for other months, that the function is set up to use the the month/year portion of the current date when it is run, and that the function will have to be rewritten to use the month/year you've picked from your combobox. You'll then have to pass this month/year value to the function.

    Welcome to TheScripts!

    Linq ;0)>

    Comment

    • puppydogbuddy
      Recognized Expert Top Contributor
      • May 2007
      • 1923

      #3
      Originally posted by jriechers
      The following is a quick example of what I am trying to do:

      ---
      Private Sub MonthCombo_Afte rUpdate(Cancel As Integer)

      [test] = First_Saturday( )

      End Sub
      ---

      Basically when the user changes the month in the form header it will update all the patch windows using their particular function.

      MonthCombo is a control box in a form

      [test] is a textbox in a form

      First_Saturday( ) is a function in a module named DateCalculation .

      Originally I had attached each function directly to related textbox as default value which worked just fine until I figured it need the flexibility of changing the month value.

      I had changed a function to replace Month(Date) with [Form]![test]![MonthCombo] which works, but only as the form loads. I need the data to update if the month is changed.

      This is the following error I get as the AfterUpdate runs...

      The expression After Update you entered as the event property setting produced the following error: Procedure declaration does not match description of event or procedure having the same name.
      Hmmm...here are some things you can try:

      1. verify that First_Saturday( ) is defined as a public function.
      2. should you be passing the month as a parameter to First_Saturday( ) .......First_Sa turday(Month)?
      3.. verify that the combobox is not the page header section of the form.
      4. if the above does not help, try the requery method as shown:

      Private Sub MonthCombo_Afte rUpdate(Cancel As Integer)
      [test] = First_Saturday( )
      Me.Requery
      End Sub

      Comment

      • FishVal
        Recognized Expert Specialist
        • Jun 2007
        • 2656

        #4
        Hi, there.

        In design view check the value of AfterUpdate property of [MonthCombo].
        It should be "[Event Procedure]".

        As an alternative solution you may perform calculation in query which is RecordSource of the form. Usually it performs faster.

        Regards,
        Fish.

        Comment

        • jriechers
          New Member
          • Mar 2008
          • 11

          #5
          Originally posted by missinglinq
          We really need to see the code for First_Saturday( ) in order to help, I think. My guess woud be that if it worked for the current month, when you had it set as a default value, but doesn't work for other months, that the function is set up to use the the month/year portion of the current date when it is run, and that the function will have to be rewritten to use the month/year you've picked from your combobox. You'll then have to pass this month/year value to the function.

          Welcome to TheScripts!

          Linq ;0)>
          Here is the Function First_Saturday( )

          Function First_Saturday( ) As Date
          For x = 0 To 6
          If Weekday(DateSer ial(Year(Date), Month(Date), 1) + x, vbUseSystemDayO fWeek) = vbSaturday Then
          First_Saturday = DateSerial(Year (Date), Month(Date), 1) + x
          End If
          Next x
          End Function

          Comment

          • jriechers
            New Member
            • Mar 2008
            • 11

            #6
            Originally posted by puppydogbuddy
            Hmmm...here are some things you can try:

            1. verify that First_Saturday( ) is defined as a public function.
            2. should you be passing the month as a parameter to First_Saturday( ) .......First_Sa turday(Month)?
            3.. verify that the combobox is not the page header section of the form.
            4. if the above does not help, try the requery method as shown:

            Private Sub MonthCombo_Afte rUpdate(Cancel As Integer)
            [test] = First_Saturday( )
            Me.Requery
            End Sub
            I assume since its just Function and not Public Function that would make it private. I tried Public Function but that didnt work either.

            If you look at a previous post in which I posted the actual Function you can see that there is no need to pass the parameter Month.

            The combobox was in the header of the form, however, it also failed in the details section.

            Me.Requery also failed. this is most likely because there are 33 functions in the form that I assume are private. I will look into this public/private thing more.

            Comment

            • missinglinq
              Recognized Expert Specialist
              • Nov 2006
              • 3533

              #7
              Originally posted by jriechers
              If you look at a previous post in which I posted the actual Function you can see that there is no need to pass the parameter Month.
              There certainly is if you want the date returned by the function to be in some month other than the current month, which you've indicated, in the bit below, is the whole reason for adding the combobox!

              Originally posted by jriechers
              Originally I had attached each function directly to related textbox as default value which worked just fine until I figured it need the flexibility of changing the month value.

              I had changed a function to replace Month(Date) with [Form]![test]![MonthCombo] which works, but only as the form loads. I need the data to update if the month is changed.
              Your idea of modifying the function to make the month variable was a step in the right direction. Assuming the function code is correct, perhaps it was placed in the wrong place. The function should probably be called from the combobox's AfterUpdate event in the code module, not from the AfterUpdate Property in the Property Sheet, which the error you reported sounds like might be the case.

              Linq ;0)>

              Comment

              • jriechers
                New Member
                • Mar 2008
                • 11

                #8
                Originally posted by missinglinq
                The function should probably be called from the combobox's AfterUpdate event in the code module, not from the AfterUpdate Property in the Property Sheet, which the error you reported sounds like might be the case.

                Linq ;0)>
                Now Im confused :-)

                I am calling an [Event Procedure] from the Combo Box: MonthCombo After Update property.

                This [Event Procedure] points to
                Private Sub MonthCombo_Afte rUpdate(Cancel As Integer)

                [test] = First_Saturday

                End Sub

                First_Saturday is the following Function
                Public Function First_Saturday( ) As Date
                For x = 0 To 6
                If Weekday(DateSer ial(Year(Date), Month(Date), 1) + x, vbUseSystemDayO fWeek) = vbSaturday Then
                First_Saturday = DateSerial(Year (Date), Month(Date), 1) + x
                End If
                Next x
                End Function

                Note: I had recently added the Public statement in front of Function earlier, but originally Public did not exist.


                In a variation of the Function, the Variable Month(Date) has been replaced with [Form]![test]![MonthCombo]. When the month is changed it is suppose to update the related textbox using the function with the new month variable.

                Comment

                • jriechers
                  New Member
                  • Mar 2008
                  • 11

                  #9
                  Woot got it to work... i was putting down Form! instead of Forms! when pointing to an object!!!!!!

                  Comment

                  • missinglinq
                    Recognized Expert Specialist
                    • Nov 2006
                    • 3533

                    #10
                    Glad you got it working!

                    Linq ;0)>

                    Comment

                    Working...