Results 1 to 9 of 9
  1. #1
    Join Date
    Nov 2007
    Posts
    11

    Unanswered: Problem with Option in a Frame

    Hi,

    I am having quite alot of trouble trying to place a set of radios inside a Frame object. Can anybody help me?

    Dim MyChk Control

    With UserForm1.Controls.Add("Forms.Frame.1", "frmQuestion")
    .Caption = "TEST"
    .Top = questionsTop
    .Left = r * 26 - 16 + 20
    .Width = 400
    End With

    Set MyChk = .frmQuestion.Controls.Add("Forms.OptionButton.1")MyChk.GroupNa me = "q_1"
    MyChk.Value = 1
    MyChk.Left = 20
    Chk.Top = 20

    Error is at .frmQuestion
    Invalid or unqualified reference


    What does this mean?

  2. #2
    Join Date
    Apr 2004
    Location
    Derbyshire, UK
    Posts
    789
    Provided Answers: 1
    Hi

    Never used dynamic control addition, but have you tried

    Set MyChk = UserForm1.frmQuestion.Controls.Add("Forms.OptionBu tton.1")MyChk.GroupNa me = "q_1"

    OR if the code is in UserForm1 perhaps this (without the period)

    Set MyChk = frmQuestion.Controls.Add("Forms.OptionButton.1")My Chk.GroupNa me = "q_1"

    You cannot use .frmQuestion without a 'With' statement such as

    With UserForm1
    OR
    With Me

    ??

    MTB

  3. #3
    Join Date
    Nov 2007
    Posts
    11
    Ah ok,

    I have opted to do it this way and seems to work fine now.

    With cFrame .Width = 560
    .Top = questionsTop
    .Left = 20
    .ZOrder (1)
    .Caption = "Question " & (n + 1)
    End With

    Set qLab = cFrame.Controls.Add("Forms.label.1", "lab", True)
    With qLab
    .Width = 450
    .Height = 10
    .Top = 5
    .Left = 10
    .ZOrder (0)
    .Caption = CStr(rst(2))
    End With

    Set cControl2 = cFrame.Controls.Add("Forms.OptionButton.1", "opt1", True)
    With cControl2
    .GroupName = "q_" + CStr(rst(0))
    .Width = 150
    .Height = 20
    .Top = 0
    .Left = 475
    .ZOrder (0)
    .Value = 1
    End With

  4. #4
    Join Date
    Nov 2007
    Posts
    11
    Sorry forgot to add this at the top

    Set cFrame = Me.Controls.Add("Forms.Frame.1", "MyFrame", True)

    many thanks

  5. #5
    Join Date
    Nov 2007
    Posts
    11
    I am having problems trying to associate an event (ie the onclick of the optionButtons) of these on the fly controls.

    Can someone explain to me how this done?

  6. #6
    Join Date
    Mar 2006
    Posts
    163
    Jim

    Can I ask what you are actually trying to achieve?

    Why are you creating these controls on the fly?

    It is possible to associate code with the controls events, what you would need would be a class module.

    I don't actually have anything at hand that deals with controls on frames.

    And I'm not sure if the click event of the option buttons will be exposed in a class module.

  7. #7
    Join Date
    Nov 2007
    Posts
    11
    Hi,

    I seem to have almost solved the problem I had.

    I am trying to generate a offline Questionnaire form which is a series of surveys that contain questions with sub parts. Hence I need to loop through a db recordset to get back my questions and generate a form with all of the controls on it.

    The problem I face is generating them dynamically and then validating them.

    This code seems to work fine until it is placed within a recordset loop

    'code on my userform is named UserForm1:

    Code:
    Option Explicit
       
      Dim OB_Coll As Collection
      Dim Pos As Integer
       
      Private Sub cmdEvent_Click()
           Dim o As MSForms.OptionButton
           Dim OBE As New OptionButtonEvents
          '
           If OB_Coll Is Nothing Then Set OB_Coll = New Collection
           
            Set o = Me.Controls.Add("Forms.OptionButton.1", , True)
           o.Caption = "Dynamically Added Option Button" & CStr(Me.Controls.Count) - 2
           o.AutoSize = True
            o.Top = Pos
           OB_Coll.Add OBE
           Call OBE.WatchControl(o, Me)
           Pos = Pos + o.Height + 4
           
           
      End Sub
    
      Friend Sub OptionButtonDblClick(o As MSForms.OptionButton)
           MsgBox o.Name & " was just double-clicked..."
      End Sub
    'code on a new class module named OptionButtonEvents
    Code:
    Option Explicit
       
      Private WithEvents ob As MSForms.OptionButton
      Private CallBackParent As UserForm1
       
      Private Sub ob_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
           Call CallBackParent.OptionButtonDblClick(ob)
      End Sub
       
      Friend Sub WatchControl(oControl As MSForms.OptionButton, oParent As UserForm1)
           Set ob = oControl
           Set CallBackParent = oParent
      End Sub
    Can anybody tell me what I would need to do to get it working in a loop.
    Would I have to use the EVAL function?

  8. #8
    Join Date
    Mar 2006
    Posts
    163
    Couldn't you just use listboxes?

  9. #9
    Join Date
    Nov 2007
    Posts
    11
    Its a possibility but I would prefer to use optionButtons as it resembles the website version.

    If I was generating list boxes on the fly wouldnt I have the same problem trying to call an event to that object?

Posting Permissions

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