do you know a method to access userform which name is stored in a variable? I have class module with events for checkboxes, but checkboxes are located on different userforms and I need to operate with them or theirs userforms.
Class module have its public variable chbParent, which is userform name. Lets say that
chParent = "formCmnStructs"
Then inside of class module I have this (and more operations where condition is required):
If chbParent = "formInsertRow" Then
Divisions(r, c).Checked = IIf(formInsertRow.Controls("chbDiv_" & Me.chbId).value = True, 1, 0)
formInsertRow.chbDivClicked
ElseIf chbParent = "formCmnStructs" Then
Divisions(r, c).Checked = IIf(formCmnStructs.Controls("chbDiv_" & Me.chbId).value = True, 1, 0)
formCmnStructs.chbDivClicked
End If
Now it is used for two forms only, but more is comming. Is there any way to cancel condition and acces userform dynamically like this:
userforms(chbParent).Controls("....
You could use public variable like ActiveForm as object
and for each userform
Private Sub UserForm_Activate()
Set ActiveForm = Me
End Sub
And then in class module ActiveForm.Controls("...
To get the form name chParent = ActiveForm.Name
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.