Results 1 to 4 of 4
  1. #1
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,877
    Thanks
    0
    Thanked 0 Times in 0 Posts

    How to Reduce the Number of Times a Sub Fires? (a2k (9.0.6926) SP-3 Jet 4.0 SP-8)

    I have a Form with a Subform.

    The Form has a Public Sub CalculateTotals() that refreshes unbound textbox totals on the Form when information changes in the Subform

    The Form has CalculateTotals in the following places:
    Private Sub cboMemberSSNoID_AfterUpdate()
    Private Sub RefreshTotals_Click()

    The Subform has Me.Parent.CalculateTotals in the following places:

    Private Sub Form_AfterDelConfirm(Status As Integer)
    Private Sub Form_Current()
    Private Sub dteVDATE_AfterUpdate()

    When I open the Form Public Sub CalculateTotals() fires 6 times
    When I go to next record Public Sub CalculateTotals() fires 2 times

    My objective is to reduce the number of times Sub CalculateTotals() fires to 1 time in each scenario described above.

    Any thoughts?

    Thanks, John

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 28 Times in 28 Posts

    Re: How to Reduce the Number of Times a Sub Fires? (a2k (9.0.6926) SP-3 Je

    It would be very complicated to avoid this and yet produce correct and consistent results. Because of the complicated way a form and a subform interact with each other, the On Current event of the form and of the subform occur multiple times when opening a form, and possibly also when moving from record to record. The first time(s) the data may not have been initialized correctly, so if you were to limit the number of times the recalculation runs, chances are that the outcome will be incorrect. So I'd suggest to leave things as they are.

  3. #3
    Silver Lounger
    Join Date
    Jun 2001
    Location
    Niagara Falls, New York, USA
    Posts
    1,877
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: How to Reduce the Number of Times a Sub Fires? (a2k (9.0.6926) SP-3 Je

    Thanks for the advice

    After entering Sub CalculateTotals() is there any way to detenine where Sub CalculateTotals() was called from?

    John

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

    Re: How to Reduce the Number of Times a Sub Fires? (a2k (9.0.6926) SP-3 Je

    You could pass an argument to CalculateTotals:

    Public Sub CalculateTotals(strCaller As String)
    ...
    Select Case strCaller
    Case "cboMemberSSNoID_AfterUpdate"
    ...
    Case ...
    ...
    End Select
    ...
    End Sub

    Private Sub cboMemberSSNoID_AfterUpdate()
    ...
    CalculateTotals "cboMemberSSNoID_AfterUpdate"
    ...
    End Sub

    etc. You could also use a global variable.

Posting Permissions

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