Consulting

Results 1 to 4 of 4

Thread: Solved: Form run time

  1. #1

    Solved: Form run time

    Hi.

    I’m working on form run time. The code is:


    [vba]Sub Test()
    Dim Frm As Object
    Dim Frame As MSForms.Frame
    Dim OptionB As MSForms.OptionButton


    Set Frm = ThisWorkbook.VBProject.VBComponents.Add(3)

    Set Frame = Frm.designer.Controls.Add("Forms.frame.1")
    With Frame
    .Name = "Frame1"
    .Caption = "Frame1"
    .Top = 5
    .Left = 5
    .Width = 75
    .Height = 40
    End With

    Set OptionB = Frm.designer.Controls.Add("Forms.optionbutton.1")

    With OptionB
    .Name = "OButton1"
    .Caption = "Female"
    .Top = 15
    .Left = 80
    .Width = 60
    .Height = 16
    End With

    Set OptionB = Frm.designer.Controls.Add("Forms.optionbutton.1")

    With OptionB
    .Name = "OButton2"
    .Caption = "Male"
    .Top = 15
    .Left = 140
    .Width = 60
    .Height = 16
    End With

    VBA.UserForms.Add(Frm.Name).Show
    ThisWorkbook.VBProject.VBComponents.Remove Frm


    End Sub
    [/vba]
    I need to group optinbuttons into the frame.

    How would I go about doing this?
    thank.

  2. #2
    VBAX Tutor mohanvijay's Avatar
    Joined
    Aug 2010
    Location
    MADURAI
    Posts
    268
    Location
    Try this
    [vba]

    Set OptionB = Frame.Controls.Add("Forms.optionbutton.1")

    [/vba]

  3. #3
    Mac Moderator VBAX Guru mikerickson's Avatar
    Joined
    May 2007
    Location
    Davis CA
    Posts
    2,778
    I noticed that the option buttons are positioned outside the visible region of the frame.

  4. #4
    Easy solution, but impossible for me without your help. thank you very much mohanvijay

    I made ​​2 +2 = 5, again 2 +2 = 5 ... infinitely often



    The final code to the correct position of the option buttom, is the following.

    [vba]Sub Test()
    Dim Frm As Object
    Dim Frame As MSForms.Frame
    Dim OptionB As MSForms.OptionButton


    Set Frm = ThisWorkbook.VBProject.VBComponents.Add(3)

    Set Frame = Frm.designer.Controls.Add("Forms.frame.1")
    With Frame
    .Name = "Frame1"
    .Caption = "Frame1"
    .Top = 5
    .Left = 5
    .Width = 75
    .Height = 60
    End With

    'Set OptionB = Frm.designer.Controls.Add("Forms.optionbutton.1")
    Set OptionB = Frame.Controls.Add("Forms.optionbutton.1")

    With OptionB
    .Name = "OButton1"
    .Caption = "Female"
    .Top = 15
    .Left = 1
    .Width = 60
    .Height = 16
    End With

    'Set OptionB = Frm.designer.Controls.Add("Forms.optionbutton.1")
    Set OptionB = Frame.Controls.Add("Forms.optionbutton.1")

    With OptionB
    .Name = "OButton2"
    .Caption = "Male"
    .Top = 30
    .Left = 1
    .Width = 60
    .Height = 16
    End With

    VBA.UserForms.Add(Frm.Name).Show
    ThisWorkbook.VBProject.VBComponents.Remove Frm

    End Sub
    [/vba]

Posting Permissions

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