Solved Dropdown Afterupdate behaviour (1 Viewer)

Romio_1968

Member
Local time
Today, 05:30
Joined
Jan 11, 2023
Messages
126
I have a dropdown menu, Usualy, it is populated by the user by picking a value. In some situations, the dropdown value is populated from annother form, using the code
Code:
     [Forms]![AddTitle_Frm]![Domain1] = Me.Domain
     [Forms]![AddTitle_Frm]![Domain1].SetFocus
[CODE]
In this situation, the value is written in the dropdown but the AfterUpdate event is not triggered.
What should I do to triger this event without human intervention?

Thank You
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Yesterday, 21:30
Joined
Feb 28, 2001
Messages
27,387
Populating a control through code does not trigger an event. You can directly call the code since it IS a subroutine. However, be aware that if you were using the long reference, it makes it look like you are doing this from another form. (I.e. you are not using the Me. reference to the control, which would make sense if this is an external reference.) If you want to call the sub, you will again need the long form of the reference. See also:

 

Josef P.

Well-known member
Local time
Today, 04:30
Joined
Feb 2, 2023
Messages
866
AfterUpdate is not triggered when the Value property is set by code. I wouldn't even try to have AfterUpdate triggered, but would redesign the code.

Principle (symbolic code only):
Code in the form with the combo box:
Code:
private sub YourCombobox_AfterUpdate()
      Call DoSomethingWithYourCombobox
end Sub

private sub DoSomethingWithYourCombobox()
   ' here is the place for your current AfterUpdate code
end Sub

Public sub SetDomain(byval NewDomain as Variant, optional Byval SetFocusToCombobox as boolean = false)
    Me.YourCombobox.Value = NewDomain
    Call DoSomethingWithYourCombobox
    if SetFocusToCombobox then
         Me.YourCombobox.SetFocus
    end if
end Sub

Call from outside:
Code:
Forms!AddTitle_Frm.SetDomain Me.Domain, True

Now, when setting a value from the outside, you don't have to know what else needs to be done. => Logic has been encapsulated.
 

Romio_1968

Member
Local time
Today, 05:30
Joined
Jan 11, 2023
Messages
126
AfterUpdate is not triggered when the Value property is set by code. I wouldn't even try to have AfterUpdate triggered, but would redesign the code.

Principle (symbolic code only):
Code in the form with the combo box:
Code:
private sub YourCombobox_AfterUpdate()
      Call DoSomethingWithYourCombobox
end Sub

private sub DoSomethingWithYourCombobox()
   ' here is the place for your current AfterUpdate code
end Sub

Public sub SetDomain(byval NewDomain as Variant, optional Byval SetFocusToCombobox as boolean = false)
    Me.YourCombobox.Value = NewDomain
    Call DoSomethingWithYourCombobox
    if SetFocusToCombobox then
         Me.YourCombobox.SetFocus
    end if
end Sub

Call from outside:
Code:
Forms!AddTitle_Frm.SetDomain Me.Domain, True

Now, when setting a value from the outside, you don't have to know what else needs to be done. => Logic has been encapsulated.
Thank You.
It worked!
 

Users who are viewing this thread

Top Bottom