Results 1 to 9 of 9
  1. #1
    Join Date
    Jul 2004
    Posts
    67

    Question Unanswered: ?events for unbound calculated form control?

    I would like to trigger an event procedure when an unbound calculated textbox changes value (due to a change in one of its argument controls).

    The AfterUpdate and OnChange events don't seem to apply to a calculated field. Anyone know what events are triggered when a calc. field updates itself?

    Here's the control's source:

    =[curQuoteBaseFee]+[curQuoteStopsFee]+[curQuoteAMFee]+[curQuoteHolidayFee]+[curQuoteHrsPrebookedFee]

    I would like to run a sub-routine whenever it changes due to a change in any of the cur fields shown. (It automatically updates itself...I just want to catch that.)

    Thanks,
    David

  2. #2
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Just create your sub and call it from the afterupdate event of all the individual fields.
    oh yeah... documentation... I have heard of that.

    *** What Do You Want In The MS Access Forum? ***

  3. #3
    Join Date
    Jul 2004
    Posts
    67
    I know I can do that, but it seems the least efficient method. If I have 5 calculated fields, each with 5 source controls, that's 25 events that need code instead of 5. Isn't there some event that is triggered when a calc. control is recalculated/updated?

    Thanks.

  4. #4
    Join Date
    Dec 2003
    Location
    Dallas, TX
    Posts
    1,004
    Quote Originally Posted by Bud
    Hi Davidmound,

    I just created a simple database to do what I think you are kinda asking, if I understand you correctly. What I did was created a few fields i.e.:
    Items, Cost, Quantity. Then I created a calculated field to total up the Cost x Quantity. What I did then was created a small line in VBA that did this:
    Whenever the quantity in the field changed to give me a MessageBox noting it was in fact being changed. I placed the code in the OnChange event of the FORM itself, not on any control. Anyway being as I'm not quite the Pro just yet I did get this first part of your hurdle accomplished, I think. See attached below. It alerts you that your "Total" field has changed be it because your Cost or Quantity changed, the Total just changed as a result of that and you get the message box. Now, you just need to figure out a way to make it pass when the value did not change. See, it gives you the message when you add a new item just the same, only I didn't know how to make it just take the entry without running the line of code. Anyhow, I tried to help some and hope this does to some degree.

    have a nice one,

    Bud
    Uh correction, I placed it in the BeforeUpdate event of the form.

  5. #5
    Join Date
    Dec 2003
    Location
    Dallas, TX
    Posts
    1,004
    Here is the attachment, sorry about that

    Bud
    Attached Files Attached Files

  6. #6
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    how about a cheat ...use the Form_Dirty() event to hide the calculated controls and display a Recalculate button.

    izy
    currently using SS 2008R2

  7. #7
    Join Date
    Dec 2003
    Location
    Dallas, TX
    Posts
    1,004
    Quote Originally Posted by izyrider
    how about a cheat ...use the Form_Dirty() event to hide the calculated controls and display a Recalculate button.

    izy
    HI izyrider and thanks, but could you explain how you do that? I know where the FormDirty part is,but how do you make it do what you just said? Help out a person not that highly advanced.

    thanks
    Bud

  8. #8
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    one possibility:



    dim CalcsAreHidden as boolean 'a form-wide variable

    private sub Form_Dirty()
    if CalcsAreHidden then exit sub
    thisCalcBox.visible = false
    thatCalcBox.visible = false
    anotherCalcBox.visible = false
    myRecalcButton.visible = true
    CalcsAreHidden = true
    end sub

    private sub myRecalcButton_Click()
    thisCalcBox.visible = true
    thisCalcBox.setfocus 'setfocus to any .visible .enabled control except the Recalc button
    thatCalcBox.visible = true
    anotherCalcBox.visible = true
    myRecalcButton.visible = false
    'and now do whatever you do to recalculate your boxes
    'here
    'here
    'and here
    CalcsAreHidden = false
    end sub

    izy
    currently using SS 2008R2

  9. #9
    Join Date
    Jul 2004
    Posts
    67
    Thanks to all of you for trying, but there are many fields on the form, so a form-wide update event would use mucho resources unnecessarily. As for the 'recalculate' button, again, so many fields change the calculated fields that the user would recalculating a dozen times.

    If no one knows an event for the calculated field, I will have to use the afterupdate event on each of the fields used in the calculation.

    Thanks again,
    David

Posting Permissions

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