Results 1 to 12 of 12
  1. #1
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1

    Unanswered: Flow control - Triggering code after combobox update

    Hullo folks, I have (what I hope is) a quicky here.

    I am trying to figure out how to get code to fire after I have programmatically changed the text of a combobox.

    I believe I have a flow control issue here.

    I have a loop that is setting values for multiple controls on a specific form. I am using a loop of the general form:

    (frm is a form variable, and arrayvalue is a dynamic string array)
    Code:
    For Each ctrl In frm.controls
       If some criteria Then
          ctrl.Value = arrayvalue(i)
       End if
    Next ctrl
    That all works dandy, but I have code associated with one of my controls that dynamically sets the controlsource of another combo box based on the new value of the first control. That code is not firing.

    Eg I have one combo box with the following value list:

    Customer Name;Company Name

    If the user select customer name, then the control source for another combo box gets set to "SELECT * FROM customer", if they select Company name, then the source gets set to "SELECT * FROM Company"

    That code looks similar to:
    Code:
    If MyCombo.Text = "Customer" Then
       MyOtherCombo.RowSource = "SELECT * FROM Customer"
    Else
       MyOthercombo.RowSource = "SELECT * FROM Company"
    End If
    The problem is this code does not fire when the first combo box is set programmatically. The value for the second combobox IS correctly assigned, but since the recordsource wasn't properly specified, nothing shows up in the combo box. I should add that this code DOES function properly if the USER selects the value from the first combobox.

    How can I get the code in the AFterUpdate (also tried OnChange) event of the first combobox to fire BEFORE the "For Each" loop moves to the next control?

    *edited for readability.
    Last edited by Teddy; 04-08-04 at 14:40.

  2. #2
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713

    Re: Flow control - Triggering code after combobox update

    Originally posted by Teddy
    Hullo folks, I have (what I hope is) a quicky here.

    I am trying to figure out how to get code to fire after I have programmatically changed the text of a combobox.

    I believe I have a flow control issue here.

    I have a loop that is setting values for multiple controls on a specific form. I am using a loop of the general form:

    (frm is a form variable, and arrayvalue is a dynamic string array)
    Code:
    For Each ctrl In frm.controls
       If some criteria Then
          ctrl.Value = arrayvalue(i)
       End if
    Next ctrl
    That all works dandy, but I have code associated with one of my controls that dynamically sets the controlsource of another combo box based on the new value of the first control.

    Eg I have one combo box with the following value list:

    Customer Name;Company Name

    If the user select customer name, then the control source for another combo box gets set to "SELECT * FROM customer", if they select Company name, then the source gets set to "SELECT * FROM Company"

    That code looks similar to:
    Code:
    If MyCombo.Text = "Customer" Then
       MyOtherCombo.RowSource = "SELECT * FROM Customer"
    Else
       MyOthercombo.RowSource = "SELECT * FROM Company"
    End If
    The problem is this code does not fire when the first combo box is set programmatically. The value for the second combobox IS correctly assigned, but since the recordsource wasn't properly specified, nothing shows up in the combo box. I should add that this code DOES function properly if the USER selects the value from the first combobox.

    How can I get the code in the AFterUpdate (also tried OnChange) event of the first combobox to fire BEFORE the "For Each" loop moves to the next control?

    *edited for readability.
    You can't automatically ... Just invoke the AfterUpdate event yourself in the code ...

  3. #3
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1

    Re: Flow control - Triggering code after combobox update

    Originally posted by M Owen
    You can't automatically ... Just invoke the AfterUpdate event yourself in the code ...
    I was afraid someone was going to say that.


  4. #4
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    I'm having some problems with the syntax for calling the AfterUpdate event of the a specific control.

    If it was on the same form, I could just call it by the control.afterupdate

    This does not seem to function properly in a dynamic loop.

    So, given a form variable (frm), and a control variant (ctrl), how can I call the afterUpdate event for each ctrl?

    I've been trying all sorts of variations on:

    Call frm(ctrl.name).AfterUpdate

    ctrl.AfterUpdate

    frm!ctrl.afterUpdate


    I'm sure this is just a syntax thing, but I'm not sure where to look. Help files + google haven't been terribly revealing yet... where should I be looking?
    Last edited by Teddy; 04-08-04 at 15:06.

  5. #5
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713

    Re: Flow control - Triggering code after combobox update

    Originally posted by Teddy
    I was afraid someone was going to say that.

    And it had to be me .... Remember that pressing a key triggers a whole host of events that cascades up the the afterupdate event ... You don't get that sequence trigger with a programmatic replacement. You have to do it yourself ...

  6. #6
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Originally posted by Teddy
    I'm having some problems with the syntax for calling the AfterUpdate event of the a specific control.

    If it was on the same form, I could just call it by the control.afterupdate

    This does not seem to function properly in a dynamic loop.

    So, given a form variable, and a ctrl variant, how can I call the afterUpdate event for each ctrl?

    I've been trying all sorts of variations on:

    Call frm(ctrl.name).AfterUpdate

    ctrl.AfterUpdate

    frm!ctrl.afterUpdate


    I'm sure this is just a syntax thing, but I'm not sure where to look. Help files + google haven't been terribly revealing yet... where should I be looking?
    IF you have the controls name ... Remeber the event naming convention MS uses ... CONTROLNAME_AfterUpdate ...

  7. #7
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Originally posted by M Owen
    IF you have the controls name ... Remeber the event naming convention MS uses ... CONTROLNAME_AfterUpdate ...
    Yeah I've been trying to play with that too. I don't know how to effectively issue the call though..

    Unless I can pass a constructed string to a Call function..?

    Like

    s = "Forms!" & frm.name & "!" & ctrl.name & "_AfterUpdate"

    Call Syntax? (s)

  8. #8
    Join Date
    Sep 2003
    Location
    MI
    Posts
    3,713
    Originally posted by Teddy
    Yeah I've been trying to play with that too. I don't know how to effectively issue the call though..

    Unless I can pass a constructed string to a Call function..?

    Like

    s = "Forms!" & frm.name & "!" & ctrl.name & "_AfterUpdate"

    Call Syntax? (s)
    I don't recall the details but I do remember a previous post on this type of topic ... Try doing a call search ... BTW, it was a few months ago ...

  9. #9
    Join Date
    Mar 2004
    Posts
    38

    Making a method publc

    Originally posted by M Owen
    I don't recall the details but I do remember a previous post on this type of topic ... Try doing a call search ... BTW, it was a few months ago ...
    What you could do - if you have a method associated with the afterupdate event, is to make that method public and then just simply call it in the code :

    myCombo_AfterUpdate

    thats it

  10. #10
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1

    Re: Making a method publc

    Originally posted by dd_plus
    What you could do - if you have a method associated with the afterupdate event, is to make that method public and then just simply call it in the code :

    myCombo_AfterUpdate

    thats it
    My current plan is a slight variation on that concept.

    I'm going to create a module for object events that I would like public access to, then reference the module from the event handler for the object.

    It's messy, and it's a hack, but it gets me up and running.

    I would still like to figure out a more effecient way of doing this.

  11. #11
    Join Date
    Mar 2003
    Location
    The Bottom of The Barrel
    Posts
    6,102
    Provided Answers: 1
    Ok, the working solution I have know is quite the hack, but it will work.... for now...

    I created a Public sub called "FireAU" on my form:

    Public Sub FireAU()
    cmbMyCombo_AfterUpdate
    End Sub

    Then I reference this public sub using the CallByName function:

    CallByName frm, "FireAU", VbMethod

    I'll be looking for a cleaner way to do this, so if anyone still has ideas, I'm open.

  12. #12
    Join Date
    Apr 2004
    Location
    outside the rim
    Posts
    1,011
    I wouldn't call it a hack! Only reverse it - put the code in Sub FireAU and place Call Me.FireAU in the AfterUpdate sub.

    If you have a procedure you want to use both AfterUpdate and OnCall, then creating a seperate Sub for that procedure is actually cleaner code. It's cleaner because when you're project becomes large - thousands of lines of code and many, many objects, you want to reuse as much as possible. In general, if you have to type a set of code more than twice, it should probably be it's own little function or prodecure.

    Notice I said "both" in the above statement - since changes that occur in code don't trigger many of the form level events (as you have discovered) they are actually different circumstances.

    You don't need to make it public (or private). Just make it "Sub FireAU" and each place you want it, insert "Call FireAU".

    To be more proper, you could type "Call Me.FireAU". The advantage of making it "Public" is that when you type "Me." the procedure will show up in the list of events and properties associated with the form.

Posting Permissions

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