Jon von der Heyden
MrExcel MVP, Moderator
- Joined
- Apr 6, 2004
- Messages
- 10,912
- Office Version
- 365
- Platform
- 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:
The property is used to load the combobox in form initialize event and combo change event.
The problem is when I clear the form for entry mode:
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.
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
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
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
Last edited: