问题
I have a unbound combo box which I am populating on form load. What I want is when user selects the combo box text, I should be able to access its value. In this case, selected item text disappears when selected but I can access its value. Below are the combo box setting. What should I do to make combo box show the selected text and at the same time I should be able to access the selected value?
ID Process
1 a
2 b
3 c
- Column Count - 2
- Column Widths - 0",1"
Row Source Type - Table/Query
Private Sub Form_Load() Dim strSQL As String strSQL = "Select ID as F1 , process_name as F2 from tblProcess" Set objRecordset = New ADODB.Recordset objRecordset.Open strSQL, objConnection, adOpenKeyset, adLockOptimistic If Not (objRecordset.EOF And objRecordset.BOF) Then Set Me.cmbProcess.Recordset = objRecordset End If objRecordset.Close Set objRecordset = Nothing End Sub
The combo box appears after selection
Combo box properties
回答1:
Does it work properly if you skip the whole objRecordset block of code and instead just insert the line after strSQL is defined:
Me.cmbProcess.RecordSource = strSQL
来源:https://stackoverflow.com/questions/37655385/unbound-combo-box-selected-text-not-showing