What's the best way to trigger activeX control change event

Jon von der Heyden

MrExcel MVP, Moderator
Joined
Apr 6, 2004
Messages
10,912
Office Version
  1. 365
Platform
  1. Windows
I have a userform with a bunch of controls. Some are comboboxes and they are dependent, fetching an array from an external database.

At some point a user might choose to 'reset' the form, clear all controls for new record entry. When this happens I want all change events to fire because they are used to regenerate the combo lists.

Generating a combo list example:
Code:
Public Property Get Divisions() As Variant
    Dim strSql As String
            
    With Me
        If CBool(Len(.cbxCountry.Text)) Then
            strSql = "SELECT DISTINCT DIVISION FROM BU_TBL WHERE COUNTRY = '" & .cbxCountry.Text & "'" & _
                     " AND SECTOR = '" & .cbxSector.Text & "';"
            Divisions = Application.Transpose(m_clsDB.RunScript(strSql).GetRows)
        Else
            Divisions = VBA.Array(vbNullString)
        End If
    End With
End Property
The property is used to load the combobox in form initialize event and combo change event.
Code:
Private Sub UserForm_Initialize()
    Call HookUp
    Call LoadRecord
    
    '// Load the dropdown lists
    With Me
        .cbxCountry.List = .Countries
        .cbxSector.List = .Sectors
        .cbxDivision.List = .Divisions
        .cbxBU.List = .Businesses
    End With
End Sub

Private Sub cbxSector_Change()
    With Me
        .cbxDivision.List = .Divisions
    End With
End Sub
The problem is when I clear the form for entry mode:
Code:
Private Sub EntryMode()
    Dim ctl As msForms.Control
    
    For Each ctl In Me.Controls
        With ctl
            If CBool(Len(.Tag)) Then
                .Object = Empty
                .Object.Locked = CBool(Split(.Tag, ";")(4))
            End If
        End With
    Next ctl
End Sub
Clearing the control does not fire the change event. Wondering if there is a cool way to trigger the change event within the loop? I don't especially want to write a line for each control who's list must be regenerated.
 
Last edited:

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).
Clearing the control does not fire the change event

Are you referring to the cbxSector combo ?

Setting the .Object=Empty should trigger the change event of the combo.
 
Upvote 0
Was the value already ""?
 
Upvote 0
Nope.

I thought it was because I was using forms control, rather than the actual control explicitly. But seems event doesn't fire even if I say cbxSector.Value = "". What's up with that?
 
Last edited:
Upvote 0
Then it ought to be working, as Jaafar said. Can you post a sample somewhere?
 
Upvote 0
Yes - if you can stick it on a file hosting site, or mail it to me if you can't provide it in public.
 
Upvote 0

Forum statistics

Threads
1,224,560
Messages
6,179,520
Members
452,921
Latest member
BBQKING

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top