Dynamically add a Frame within a Frame

anuragsapanbharat

New Member
Joined
Mar 9, 2010
Messages
2
Hi,

I have been trying to create a runtime frame control, which I am having issue to create within another existing frame.
When I am adding a frame to the Userform Set cCont = Me.Controls.Add("Forms.frame.1", "NewFrame") its working fine. But the same is not working for the below code Set cCont = Frame1.Controls.Add("Forms.frame.1", "NewFrame"), where Frame1 is already there on the form. I am getting Automation error. the object invoked disconnected from its clients.

I searched google but there is no solution for the same. Please help.
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
This worked fine for me.
Code:
Dim cCont As MSForms.Control

Set cCont = Me.Frame1.Controls.Add("Forms.Frame.1","NewFrame")

With cCont
    .Top = 5: .Left = 2
    .Height = 50: .Width = 100
    .Caption = "Run Time"
End With

I'm curious about the name. Why are you giving the new frame a fixed name? You already "have" the frame in a variable.
It may not be the actual creation of the frame that is causing an error, but something downstream.
 
Upvote 0
If you're creating the frames in separate procedures, try...

Code:
Set cCont = Me.Controls.Add("Forms.Frame.1", "Frame1")

and

Code:
Set cCont = Me.Controls("Frame1").Controls.Add("Forms.Frame.1", "Frame2")

Within the same procedure, try...

Code:
    Dim Frame1 As MsForms.Frame
    Dim Frame2 As MsForms.Frame
    Set Frame1 = Me.Controls.Add("Forms.Frame.1", "MyFrame1")
    Set Frame2 = Frame1.Controls.Add("Forms.Frame.1", "MyFrame2")

Hope this helps!
 
Upvote 0

Forum statistics

Threads
1,215,401
Messages
6,124,705
Members
449,182
Latest member
mrlanc20

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top