simple userform code

Discussion in 'AutoCAD' started by johnbortoli, Feb 4, 2005.

  1. johnbortoli

    johnbortoli Guest

    I have asimple userform which consists of 2 option buttons (1 and 2) and one combo box (with choice of a b c and d). What i want to do is have user select one or the other option buttons (1 or 2) and the combobox display a and b if option button 1 selected or c and d if option button 2 selected.
    Then user selects a or b or c or d and the result to be saved as an attribute for a block insertion. Can anyone supply mewith some code to do this
     
    johnbortoli, Feb 4, 2005
    #1
  2. In the click event handler for each option button, clear the contents of
    the combobox and refill it with the appropriate values.
     
    Frank Oquendo, Feb 4, 2005
    #2
  3. johnbortoli

    johnbortoli Guest

    how do i do that. i am just a new programmer
     
    johnbortoli, Feb 4, 2005
    #3
  4. johnbortoli

    johnbortoli Guest

    this is what i have at present


    Private Sub OptionButton1_Click()
    If OptionButton1 = True Then
    Cbofirstend.AddItem "a"
    Cbofirstend.AddItem "b"
    Cbofirstend.ListIndex = 1
    End If
    If OptionButton2 = True Then
    'clear combobox'

    Cbofirstend.AddItem "c"
    Cbofirstend.AddItem "d"
    Cbofirstend.ListIndex = 1
    End If
    End Sub
     
    johnbortoli, Feb 4, 2005
    #4
  5. Almost there. Separate the two blocks of code; the top section in
    OptionButton1_Click, the bootm section in OptionButton2_Click.

    Next, be sure to clear the Combobox before you start adding items to it.
     
    Frank Oquendo, Feb 4, 2005
    #5
  6. johnbortoli

    VBA Guest

    Private Sub OptionButton1_Click()
    With ComboBox1
    .Clear
    .AddItem "A"
    .AddItem "B"
    .ListIndex = 0
    End With
    End Sub

    Private Sub OptionButton2_Click()
    With ComboBox1
    .Clear
    .AddItem "C"
    .AddItem "D"
    .ListIndex = 0
    End With
    End Sub

    No need for any "if then" construct
     
    VBA, Feb 4, 2005
    #6
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.