+ Reply to Thread
Results 1 to 5 of 5

Add controls to Frames at Runtime

  1. #1
    Neily
    Guest

    Add controls to Frames at Runtime

    Hi,

    I am using the following code to add a frame to a form..
    Set AddMyControl = Controls.Add("Forms.Frame.1", "fraFrame1", Visible)
    AddMyControl.Left = 50
    AddMyControl.Top = 50
    AddMyControl.Caption = "New Frame Box"
    AddMyControl.Width = 70
    AddMyControl.Height = 50

    I then want to add, say a checkbox into that frame. Anybody done this
    before, got any ideas how it codes?

    Thanks.

  2. #2
    Bob Phillips
    Guest

    Re: Add controls to Frames at Runtime

    Neily,

    Here is some example code

    Private Sub CreateControl()
    Dim newButton As msforms.Control
    Select Case True
    Case chkText.Value
    Set newButton = Me.Controls.Add("Forms.Textbox.1")
    newButton.Name = "New Textbox"
    Case chkButton.Value
    Set newButton = Me.Controls.Add("Forms.CommandButton.1")
    newButton.Caption = "newCmd"
    Case chkCheckbox.Value
    Set newButton = Me.Controls.Add("Forms.Checkbox.1")
    newButton.Caption = "Another Checkbox"
    End Select

    With newButton
    .Left = 100
    .Top = 50
    .Visible = True
    End With

    End Sub

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "Neily" <[email protected]> wrote in message
    news:[email protected]...
    > Hi,
    >
    > I am using the following code to add a frame to a form..
    > Set AddMyControl = Controls.Add("Forms.Frame.1", "fraFrame1", Visible)
    > AddMyControl.Left = 50
    > AddMyControl.Top = 50
    > AddMyControl.Caption = "New Frame Box"
    > AddMyControl.Width = 70
    > AddMyControl.Height = 50
    >
    > I then want to add, say a checkbox into that frame. Anybody done this
    > before, got any ideas how it codes?
    >
    > Thanks.




  3. #3
    Neily
    Guest

    Re: Add controls to Frames at Runtime

    Hi Bob,

    Thanks for the reply. What does this code do? Is that just to add controls
    to the form?

    What I'm trying to acheive is to create a Frame at runtime (which I have
    from the original post) and then, still at run time, add 2 Option Buttons to
    that frame so that they are grouped using that frame.

    You know how I can do that?

    Ta.

    Neil

    "Bob Phillips" wrote:

    > Neily,
    >
    > Here is some example code
    >
    > Private Sub CreateControl()
    > Dim newButton As msforms.Control
    > Select Case True
    > Case chkText.Value
    > Set newButton = Me.Controls.Add("Forms.Textbox.1")
    > newButton.Name = "New Textbox"
    > Case chkButton.Value
    > Set newButton = Me.Controls.Add("Forms.CommandButton.1")
    > newButton.Caption = "newCmd"
    > Case chkCheckbox.Value
    > Set newButton = Me.Controls.Add("Forms.Checkbox.1")
    > newButton.Caption = "Another Checkbox"
    > End Select
    >
    > With newButton
    > .Left = 100
    > .Top = 50
    > .Visible = True
    > End With
    >
    > End Sub
    >
    > --
    >
    > HTH
    >
    > RP
    > (remove nothere from the email address if mailing direct)
    >
    >
    > "Neily" <[email protected]> wrote in message
    > news:[email protected]...
    > > Hi,
    > >
    > > I am using the following code to add a frame to a form..
    > > Set AddMyControl = Controls.Add("Forms.Frame.1", "fraFrame1", Visible)
    > > AddMyControl.Left = 50
    > > AddMyControl.Top = 50
    > > AddMyControl.Caption = "New Frame Box"
    > > AddMyControl.Width = 70
    > > AddMyControl.Height = 50
    > >
    > > I then want to add, say a checkbox into that frame. Anybody done this
    > > before, got any ideas how it codes?
    > >
    > > Thanks.

    >
    >
    >


  4. #4
    Peter T
    Guest

    Re: Add controls to Frames at Runtime

    try adding the following to your sample code

    Dim addFrameCtrl as control
    ' AddMyControl code

    With AddMyControl
    Set addFrameCtrl = .Controls.Add("Forms.Textbox.1")
    'whatever other properties, eg
    addFrameCtrl.Text = "Textbox in frame"
    'add more controls to the frame
    End With

    or similar without an object ref to the frame
    With Me.Controls("fraFrame1")

    or maybe
    Set addFrameCtrl = Me.Controls("fraFrame1").Controls.Add("Forms.Textbox.1")

    Regards,
    Peter T

    "Neily" <[email protected]> wrote in message
    news:[email protected]...
    > Hi,
    >
    > I am using the following code to add a frame to a form..
    > Set AddMyControl = Controls.Add("Forms.Frame.1", "fraFrame1", Visible)
    > AddMyControl.Left = 50
    > AddMyControl.Top = 50
    > AddMyControl.Caption = "New Frame Box"
    > AddMyControl.Width = 70
    > AddMyControl.Height = 50
    >
    > I then want to add, say a checkbox into that frame. Anybody done this
    > before, got any ideas how it codes?
    >
    > Thanks.




  5. #5
    Bob Phillips
    Guest

    Re: Add controls to Frames at Runtime

    This was just show you how to add other controls. You will need to add into
    your code.

    --

    HTH

    RP
    (remove nothere from the email address if mailing direct)


    "Neily" <[email protected]> wrote in message
    news:[email protected]...
    > Hi Bob,
    >
    > Thanks for the reply. What does this code do? Is that just to add

    controls
    > to the form?
    >
    > What I'm trying to acheive is to create a Frame at runtime (which I have
    > from the original post) and then, still at run time, add 2 Option Buttons

    to
    > that frame so that they are grouped using that frame.
    >
    > You know how I can do that?
    >
    > Ta.
    >
    > Neil
    >
    > "Bob Phillips" wrote:
    >
    > > Neily,
    > >
    > > Here is some example code
    > >
    > > Private Sub CreateControl()
    > > Dim newButton As msforms.Control
    > > Select Case True
    > > Case chkText.Value
    > > Set newButton = Me.Controls.Add("Forms.Textbox.1")
    > > newButton.Name = "New Textbox"
    > > Case chkButton.Value
    > > Set newButton = Me.Controls.Add("Forms.CommandButton.1")
    > > newButton.Caption = "newCmd"
    > > Case chkCheckbox.Value
    > > Set newButton = Me.Controls.Add("Forms.Checkbox.1")
    > > newButton.Caption = "Another Checkbox"
    > > End Select
    > >
    > > With newButton
    > > .Left = 100
    > > .Top = 50
    > > .Visible = True
    > > End With
    > >
    > > End Sub
    > >
    > > --
    > >
    > > HTH
    > >
    > > RP
    > > (remove nothere from the email address if mailing direct)
    > >
    > >
    > > "Neily" <[email protected]> wrote in message
    > > news:[email protected]...
    > > > Hi,
    > > >
    > > > I am using the following code to add a frame to a form..
    > > > Set AddMyControl = Controls.Add("Forms.Frame.1", "fraFrame1",

    Visible)
    > > > AddMyControl.Left = 50
    > > > AddMyControl.Top = 50
    > > > AddMyControl.Caption = "New Frame Box"
    > > > AddMyControl.Width = 70
    > > > AddMyControl.Height = 50
    > > >
    > > > I then want to add, say a checkbox into that frame. Anybody done this
    > > > before, got any ideas how it codes?
    > > >
    > > > Thanks.

    > >
    > >
    > >




+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1