Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Wes Wes is offline
external usenet poster
 
Posts: 26
Default programatically inserting a control within a frame

I'm creating a section of a userform on the fly. I can create a frame using
the code:

Set MyControl = Controls.Add("Forms.Frame.1")
With MyControl
.width = 200
.height = 400
.top = 160
.left = 2
.zorder (1)
end with

now I want to create a textbox and a label within this frame (actually a
bunch of them). Anytime a create the textboxes or labels, it goes behind the
frame. I used zorder(0) on the textbox. I also switched the zorder of the
frame and textbox. (Not sure if this would have had anything to do with it
anyhow.)

Thanks in advance for your help
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,489
Default programatically inserting a control within a frame

Hi,

You need to add the controls to the frame rather than the userform.

Dim MyControl As MSForms.Frame
Dim MyLabel As MSForms.Label

Set MyControl = Controls.Add("Forms.Frame.1")
With MyControl
.Width = 200
.Height = 400
.Top = 160
.Left = 2
.ZOrder (1)
.Visible = True
End With

Set MyLabel = MyControl.Controls.Add("Forms.Label.1")
With MyLabel
.Width = 100
.Height = 40
.Top = 10
.Left = 2
.Caption = "Hello World"
.Visible = True
End With

Cheers
Andy
--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info
"Wes" wrote in message
...
I'm creating a section of a userform on the fly. I can create a frame
using
the code:

Set MyControl = Controls.Add("Forms.Frame.1")
With MyControl
.width = 200
.height = 400
.top = 160
.left = 2
.zorder (1)
end with

now I want to create a textbox and a label within this frame (actually a
bunch of them). Anytime a create the textboxes or labels, it goes behind
the
frame. I used zorder(0) on the textbox. I also switched the zorder of
the
frame and textbox. (Not sure if this would have had anything to do with it
anyhow.)

Thanks in advance for your help


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default programatically inserting a control within a frame

By default new controls are added to the form. If you want them added to
some other container, eg a frame or multipage, you need to qualify.

Set myControl2 = Me.Frame1.Controls.Add(etc 'if Frame1 was added at design
time
or
Set myControl2 = Me.Controls("Frame1").Controls.Add(etc

or in your case you could do
Set myControl2 = MyControl.Add(etc

or even

With MyControl
.Left = 2
.Controls.add(Forms.Textbox.1") ' note the preceding dot
.BackColor = 255
End With
End with

Regards,
Peter T

"Wes" wrote in message
...
I'm creating a section of a userform on the fly. I can create a frame

using
the code:

Set MyControl = Controls.Add("Forms.Frame.1")
With MyControl
.width = 200
.height = 400
.top = 160
.left = 2
.zorder (1)
end with

now I want to create a textbox and a label within this frame (actually a
bunch of them). Anytime a create the textboxes or labels, it goes behind

the
frame. I used zorder(0) on the textbox. I also switched the zorder of

the
frame and textbox. (Not sure if this would have had anything to do with it
anyhow.)

Thanks in advance for your help



  #4   Report Post  
Posted to microsoft.public.excel.programming
Wes Wes is offline
external usenet poster
 
Posts: 26
Default programatically inserting a control within a frame

Thanks very much for your help this works perfect.

Wes

"Andy Pope" wrote:

Hi,

You need to add the controls to the frame rather than the userform.

Dim MyControl As MSForms.Frame
Dim MyLabel As MSForms.Label

Set MyControl = Controls.Add("Forms.Frame.1")
With MyControl
.Width = 200
.Height = 400
.Top = 160
.Left = 2
.ZOrder (1)
.Visible = True
End With

Set MyLabel = MyControl.Controls.Add("Forms.Label.1")
With MyLabel
.Width = 100
.Height = 40
.Top = 10
.Left = 2
.Caption = "Hello World"
.Visible = True
End With

Cheers
Andy
--

Andy Pope, Microsoft MVP - Excel
http://www.andypope.info
"Wes" wrote in message
...
I'm creating a section of a userform on the fly. I can create a frame
using
the code:

Set MyControl = Controls.Add("Forms.Frame.1")
With MyControl
.width = 200
.height = 400
.top = 160
.left = 2
.zorder (1)
end with

now I want to create a textbox and a label within this frame (actually a
bunch of them). Anytime a create the textboxes or labels, it goes behind
the
frame. I used zorder(0) on the textbox. I also switched the zorder of
the
frame and textbox. (Not sure if this would have had anything to do with it
anyhow.)

Thanks in advance for your help



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
frame control inside an image control moniong Excel Programming 2 March 30th 07 03:29 AM
Frame from Control Toolbox?! [email protected] Excel Programming 1 June 17th 06 10:07 PM
Use VBA to control scrollbars in a Frame gary Excel Programming 0 May 26th 06 10:17 PM
Programatically control picture property of Image control Brassman[_5_] Excel Programming 5 May 24th 05 09:32 PM
tab order in frame control mike Excel Programming 2 February 19th 04 03:42 PM


All times are GMT +1. The time now is 11:22 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"