Set Combo Box Record Source
Posted on 2002-07-05
Right now I have this situation:
The Source for the form frmUser is tblUser.
One of the fields of this table is called UserContact (Long Integer). The txtContact textbox (Hidden) is bound to this field.
The cmbContact combobox is unbound and used to display the contacts (qryContactsCombo is the command object name).
The combo box gets it's values through this code:
' SET COMBO BOX
Dim conn As New ADODB.Connection
Dim RecSet As New ADODB.Recordset
Dim sSQL As String
RecSet.Open "SELECT * FROM tblContacts", conn, adOpenStatic, adLockReadOnly
If RecSet.RecordCount <= 0 Then Exit Sub
Do Until RecSet.EOF
cmbContact.ItemData(cmbContact.NewIndex) = RecSet.Fields("ConId")
If RecSet.Fields("ConId") = txtContact Then
cmbContact.ListIndex = cmbContact.NewIndex
Set RecSet = Nothing
Set conn = Nothing
When I change the value in the combobox then the value from ItemData will be saved in the txtContact.
I am exploring for the first time the Data Environement control. I was hoping to be able to get the values for the combobox directly from the Data Environement control into the combobox. So I wouldn't need the code above. The command object looks like this right now:
SELECT ConQuickName, ConId
ORDER BY ConQuickName
I need to display ConQuickName in the combobox.
The saved value should be ConId (right now in the ItemData property of the combobox or whereever it needs to be).
Is it possible to get this by setting the properties of the combobox without using the txtContact textbox?
Actually it is similar to access where you would use the RecordSource, RowSource and BoundColumn property. Can this be done?