Identifying controls on MultiPage Pages

R

Rhumba

Hi,

I would like to present a userform to my customers that has on it a
multipage with a number of pages, and on each page a varying number of
checkboxes.

Say there are two pages, "Page1" and "Page2," and later when I'm
running through all of the checkboxes in code, I'd like to know from
which page each checkbox that's checked came from.

I usually use something like this on the form:

Private Sub CommandButton1_Click()
Dim i As Integer
Dim obj as Object

For Each obj In Me.Controls
If TypeName(obj) = "CheckBox" Then
If obj.value = True Then
...
End If
End If
Next

If any given checkbox is checked, is there a way to tell which page it
was on? Although VBA Help indicates each Page of a MultiPage can act
as a container for controls, I have had no luck trying to link a
checkbox to a Page after the fact.

TIA for any help.
 
L

Leith Ross

Hello Rhumba,

This code will return the owner of any CheckBox that is checked. The
Parent property will return the name of the "Container" object for the
control. Some common container objects are UserForms, Frames, and
MultiPage objects. If you have a Checkbox in a Frame, the first
instance of the Parent property is the name of the Frame, the second is
the MultiPage, and then the UserForm.

For Each Ctrl In Me.Controls
If TypeName(Ctrl) = "CheckBox" And Ctrl.Object.Value = True
Then
Owner = Ctrl.Parent.Name
End If
Next Ctrl


To get the CheckBox Owner on a Frame would be...
Owner = Ctrl.Parent.Parent.Name

Sincerely,
Leith Ross
 
R

Rhumba

Hello Rhumba,

This code will return the owner of any CheckBox that is checked. The
Parent property will return the name of the "Container" object for the
control. Some common container objects are UserForms, Frames, and
MultiPage objects. If you have a Checkbox in a Frame, the first
instance of the Parent property is the name of the Frame, the second is
the MultiPage, and then the UserForm.

For Each Ctrl In Me.Controls
If TypeName(Ctrl) = "CheckBox" And Ctrl.Object.Value = True
Then
Owner = Ctrl.Parent.Name
End If
Next Ctrl


To get the CheckBox Owner on a Frame would be...
Owner = Ctrl.Parent.Parent.Name

Sincerely,
Leith Ross


Hi Leith,

I had tried the Parent property previously, but apparently didn't have
the correct syntax. Many thanks for a very clear explanation!

Regards,
Rhumba
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top