Lawyer Luddite
asked on
VBA How to select combo box value based on given value
I have a Word VBA form that contains a combo/drop-down list box. The selections in this box are loaded in the VBA code via an array.
When the form loads I want a particular value to be selected based on the value previously stored in that box which I have saved (for simplicity here) to a variable called MyValue.
Therefore the selection I want displayed is that with the numerical value MyValue.
The combobox control has two columns, the bound column (numeric) is 1 but only column 2 (text) is displayed (colmn widths 0 pt;200 pt).
For instance the values/displayed text might be:
12/Choice 1
14/Choice 2
17/Choice 3
27/Choice 4
but the actual values in the control can vary each time as can the number and position of the choices.
If say I have a MyValue of 17 then I want Choice 3 displayed.
I can see how to do this using a positional reference, in this case it would be (2), assuming option base zero, but I dont know that MyValue 17 will be in position (2) because this can change.
The question therefore is how to select the displayed value I want based on the MyValue I am passing to the form?
When the form loads I want a particular value to be selected based on the value previously stored in that box which I have saved (for simplicity here) to a variable called MyValue.
Therefore the selection I want displayed is that with the numerical value MyValue.
The combobox control has two columns, the bound column (numeric) is 1 but only column 2 (text) is displayed (colmn widths 0 pt;200 pt).
For instance the values/displayed text might be:
12/Choice 1
14/Choice 2
17/Choice 3
27/Choice 4
but the actual values in the control can vary each time as can the number and position of the choices.
If say I have a MyValue of 17 then I want Choice 3 displayed.
I can see how to do this using a positional reference, in this case it would be (2), assuming option base zero, but I dont know that MyValue 17 will be in position (2) because this can change.
The question therefore is how to select the displayed value I want based on the MyValue I am passing to the form?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER