Something else to keep in mind, one can retrieve more than one selected value from a combo or list box, provided that the RowSource contains 2 or more columns of data, regardless of the Control Source.
One of the other properties in a combo box control is the .Column property. For example, if you create a 2-column combo box (it can be bound or unbound as well), you can retrieve 2 columns of data from a selected row within the AfterUpdate property once the user has made a selection. A sample SELECT query used for the combo box's rowsource could be:
"SELECT DATE, CUSTOMER FROM CUSTOMER_ORDERS ORDER BY DATE, CUSTOMER"
Here, you have a 2-column combo box (ColumnCount = 2). You can use the AfterUpdate() property from the combo box to retrieve the two values from the user and display the selected row in a bound form like this:
Private Sub cboDateCust_AfterUpdate()
Dim rs As DAO.Recordset
Dim strSearchString As String
Dim varDate As Variant
Dim varCustomer As Variant
varDate = Me.cboDateCust.Column(0)
varCustomer = Me.cboDateCust.Column(1)
' to go to the selected row, assuming customer is numeric (no quotes)
strSearchString = "DATE = #" & varDate & "# AND CUSTOMER = " & varCustomer
Set rs = Me.RecordsetClone
rs.FindFirst
Me.Bookmark = rs.Bookmark
rs.Close
End Sub
When using the .Column property in a combo or list box, enumeration starts with 0, which means the first column is Column(0), the second column is Column(1), etc.
Grant you, I'm a little bit of a dinosaur from the v1.1 days of MS Access using DAO here, but I haven't found a way to do bookmarking with ADO (open to suggestions, however).
If you DO use the "Dim rs As DAO.Recordset" as I have used in this example, be sure to check "Microsoft DAO 3.6 Object Library" (or "2.5/3.51", whichever is in your list) from Tools | References in your VBA editor.
|