Question : Combo listfillrange property changes based on user selection

I would like to have a combo box that changes it's listfill range property based on selection the user makes.
basically when it is clicked a message box or something asks if this is employees or equipment.  If for employees then the combo will show the list for employees. For equipment, then the combo will bring up the list for equipment.

how is this best done.  Thanks in advance.

Answer : Combo listfillrange property changes based on user selection

<basically when it is clicked a message box or something asks if this is employees or equipment.>

As far as I know the combobox's list must be loaded *before* the combobox is clicked.
So it seems that you may have to find another way to activate the choice.
Perhaps you could try it when the Form is initialized, or create a option group, or a make master combobox, ...
(Again, this only illustrates why this is nonstandard functionality.)

In any event, ...the code could be something like this:

'Create the variable
Dim strWhatList As String
   
    'Load the variable with whatever text the user enters in the inputbox
    strWhatList = InputBox("What List?" & vbCrLf & "(Enter: 'EM' for Employees, or 'EQ', for Equiptment)")
   
    'If the user clicks "Cancel",
    'exit the sub with no lists loaded into the combobox
    If strWhatList = "" Then
        'Display a message, then open the form
        '(without a list in the combobox)
        MsgBox "No list selected to load the combobox.", vbInformation
        'Exit
        Exit Sub
    ElseIf strWhatList = "EM" Or strWhatList = "em" Then
        'Load the appropriate list range
        Me.cboWhatList.RowSource = "=Sheet1!A2:A8"
        'Set the combobox label
        Me.lblWhatList.Caption = "Employees"
    ElseIf strWhatList = "EQ" Or strWhatList = "eq" Then
        Me.cboWhatList.RowSource = "=Sheet1!B2:B6"
        Me.lblWhatList.Caption = "Equiptment"
    Else
        MsgBox "Invalid value, no list loaded in the combobox.", vbInformation
        Exit Sub
    End If

I am sure you you will be able to adapt this to work in your database.


I have attached a sample

;-)

JeffCoachman
Random Solutions  
 
programming4us programming4us