What property locates a control on a tab page?

G

Guest

I'm writing code to create a tabbed form with controls on each of the tab
pages. (There will be over a hundred buttons, and certain buttons will
occasionally need to be added or deleted or repositioned. Rather than
clicking and dragging these hundreds of buttons by hand, and revising them -
again by hand, the code will create -and re-create as necessary- the form.)
The problem is that although the controls have properties denoting the X and
Y coordinates (i.e. the location of the control on the form), I cannot find a
property which would show which tab page the control is to be placed on. I
have also looked at the properties of other objects within the form, and have
found nothing.

To recap, what is the property that indicates what page of a tabbed form a
control appears on, and what object is it a property of?

Anyone?
 
D

Douglas J. Steele

Look at the control's Parent property.

I just cobbled together a simple test with 3 command buttons and a tab
control on a form. I named the button that I placed on Page1
"cmdButtonOnPage1", the button on Page 2 "cmdButtonOnPage2" and the button
that was on the form itself "cmdButtonOnForm". In the form's Load event, I
had the following code:

Private Sub Form_Load()
Dim ctlCurr As Control

For Each ctlCurr In Me.Controls
Debug.Print ctlCurr.Name & " is on " & _
ctlCurr.Parent.Name
Next ctlCurr

End Sub

Here's what showed up in the Immediate window:

TabCtl0 is on Form1
Page1 is on TabCtl0
cmdButtonOnPage1 is on Page1
Page2 is on TabCtl0
cmdButtonOnPage2 is on Page2
cmdButtonOnForm is on Form1
 
G

Guest

Doug:

Thanks for the help !!!
(i) Okay, so howcum the properties sheet for the control doesn't show the
"parent" property?

I'm thinking that when I write the program to create the form, each line
will set a control property. For example, the line that defines the "Y"
position of a control named "control_name" would be as follows:

Me.control_name.Top = 3240

(ii) So, to position the control on a particular tab sheet, do I write

Me.control_name.parent.name = tab_sheet_1 (???)

or do I write

Me.control_name.parent = tab_sheet_1 (???)

or is it

Me.control_name.parent = "tab_sheet_1" (???)

or perhaps (I'm wondering) this property doesn't fit into this
type of statement at all ( a: Because the property isn't on the properties
sheet, and b: Because I cannot get a response to "? Me.control_name.parent"
in the immediate window.)

I apologize for my ignorance. I'm still relatively new at this. I have a
business that needs to be automated a lot more, and I'm teaching myself to do
this stuff. I've already automated a lot, but my methodology has been
relatively clumsy. I'm trying to do things more efficiently, and to
anticipate the need for ongoing change to the programs I create.

Again, thank you very much for your kind assistance.





-----------------------
 
D

Douglas J. Steele

I suspect it's not in the Properties sheet because you can't manipulate it
(it's read-only both in Design and Run-time). The CreateControl function
allows you to specify the name of the parent control (as does the
CreateReportControl function), so you'd specify "Page1" when creating the
control.

The Parent property returns a reference to a control. You can't use Me in
the immediate window (unless you're in the midst of Debugging), but if you
put Forms("MyForm").control_name.Parent, you'd be getting a reference to an
object, so it doesn't buy you much. On the other hand,
?Forms("MyForm").control_name.Parent.Name should give you the name of the
control or form that's the parent for "control_name"

Just a comment about what you're trying to do. You said "the code will
create -and re-create as necessary- the form.". Be aware that there's a
limit to how many controls a form can have over its lifetime (it's 754). You
don't want to re-create controls on the form if you don't have to.
 

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