Results 1 to 3 of 3

Thread: combobox

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2006
    Posts
    50

    combobox

    I have a userform which enables the user to input various items of data. The userform also has a combobox whose 'rowsource' is dependant on one of the other criteria input using the userform.

    I can set up the rowsource using hidden worksheets on excel, but ideally I would like to specify the 'rowsource' within the code.

    I have following code to select what appears in combobox -
    VB Code:
    1. Private Sub ComboBox1_Click()
    2.     If Numeric_Amount < 500 Then
    3.         If Numeric_Amount = 0 Or Numeric_Amount = "" Then
    4.             MsgBox ("An Amount needs entering before a level of authorisation can be selected.")
    5.             Else
    6.             Auth = 1
    7.             Else
    8.             If Numeric_Amount >= 500 And Numeric_Amount < 2000 Then
    9.                 Auth = 2
    10.                 Else
    11.                 Auth = 3
    12.             End If
    13.         End If
    14.     End If
    15.     Select Case Auth
    16.         Case 1
    17.             Auth_Name.AddItem "Name1"
    18.             Auth_Name.AddItem "Name2"
    19.             Auth_Name.AddItem "Name3"
    20.             Auth_Name.AddItem "Name4"
    21.             Auth_Name.AddItem "Name5"
    22.         Case 2
    23.             Auth_Name.AddItem "Name1"
    24.             Auth_Name.AddItem "Name2"
    25.             Auth_Name.AddItem "Name3"
    26.             Auth_Name.AddItem "Name4"
    27.         Case 3
    28.             Auth_Name.AddItem "Name1"
    29.             Auth_Name.AddItem "Name2"
    30.             Auth_Name.AddItem "Name3"
    31.         Case Else
    32.             MsgBox ("An amount needs entering before level of Authorisation can be selected.")
    33.     End Select
    34. End Sub
    Now, I would expect that when the drop down combobox is selected on the userform this sub will kick in but it doesn't. This works with radio buttons, etc, but not this combobox.

    Any help with the above would be greatly appreciated.










    Edit: Added [vbcode][/vbcode] tags for more clarity. - Hack
    Last edited by Hack; Jan 4th, 2006 at 12:31 PM.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: combobox

    Moved to Office Development

  3. #3
    Frenzied Member DKenny's Avatar
    Join Date
    Sep 2005
    Location
    on the good ship oblivion..
    Posts
    1,171

    Re: combobox

    Quote Originally Posted by mikeymay
    I would expect that when the drop down combobox is selected on the userform this sub will kick in but it doesn't. This works with radio buttons, etc, but not this combobox.
    You should use the _Change event instead of the _Click event.


    Quote Originally Posted by mikeymay
    I can set up the rowsource using hidden worksheets on excel, but ideally I would like to specify the 'rowsource' within the code.
    If you have the data in a range you could use the following sub to loop through that range a specific number of times and add the values to the 2nd combobox.


    VB Code:
    1. Sub FillBox2(RowCount As Integer)
    2. Dim MyRange As Range
    3. Dim CellNum As Integer
    4.    
    5.     'Reset the 2nd Combobox
    6.     Auth_Name.Clear
    7.    
    8.     'The range containing the list items for the Auth_Name CB
    9.     'You will need to prefix the range with a worksheet name, if the range is on a seperate sheet
    10.     Set MyRange = Range("your Range Name here")
    11.    
    12.     'Loop through the range
    13.     For CellNum = 1 To RowCount
    14.         'Add the item
    15.         Auth_Name.AddItem MyRange.Cells(CellNum, 1)
    16.     Next CellNum
    17.    
    18.     'Select the 1st possible venue
    19.     Auth_Name.ListIndex = 0
    20.    
    21.     Set MyRange = Nothing
    22. End Sub


    Then your Select Case statement becomes...

    VB Code:
    1. Select Case Auth
    2.     Case 1
    3.         FillBox2 5
    4.     Case 2
    5.         FillBox2 4
    6.     Case 3
    7.         FillBox2 3
    8.     Case Else
    9.         MsgBox ("An amount needs entering before level of Authorisation can be selected.")
    10. End Select
    Declan

    Don't forget to mark your Thread as resolved.
    Take a moment to rate posts that you think are helpful

Posting Permissions

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



Click Here to Expand Forum to Full Width