ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Identifying controls on MultiPage Pages (https://www.excelbanter.com/excel-programming/352598-identifying-controls-multipage-pages.html)

Rhumba

Identifying controls on MultiPage Pages
 
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.


Leith Ross[_537_]

Identifying controls on MultiPage Pages
 

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


--
Leith Ross
------------------------------------------------------------------------
Leith Ross's Profile: http://www.excelforum.com/member.php...o&userid=18465
View this thread: http://www.excelforum.com/showthread...hreadid=509221


Rhumba

Identifying controls on MultiPage Pages
 
On Tue, 7 Feb 2006 02:31:29 -0600, Leith Ross
wrote:


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



All times are GMT +1. The time now is 10:41 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com