How to select an item from a listbox?

shaneucc

Registered User.
Local time
Today, 23:12
Joined
Jul 25, 2013
Messages
28
At the moment I have a query that returns a result based on what's selected in a combobox.
SELECT ComponentT.ComponentType AS ComponentType
FROM ComponentT
WHERE (((ComponentT.TotalComponent) Like [Forms]![DeviceF]![D_ComponentNameCmb] & "*"));

Instead of this I want to rewrite the query to return a result based on what the user has selected in a list box of items. How would this query look. Would I need to increment it in a loop checking all entries into the list box as it can vary in size and if so how?

I tried changing the last line to WHERE (((ComponentT.TotalComponent) Like [Forms]![DeviceF]![D_OutputLsb].[ItemsSelected] & "*")); which returned a result just not the right one. Is there something wrong with the syntax?
 
Last edited:
Hello shaneucc, you description is quiet not elaborate.. Do you wish to replace the ComboBox with the ListBox? And thus return a result? Is it possible to give some example?

With the above Code, the suggestion I would have is take away the LIKE operator as the ComboBox will always have a complete value, part value searches are for Text boxes..
 
As it stands now I have a combo box which displays a unique value from a table. Based on which entry the user selects in this combo box a text box will display a different field of information from the table corresponding to the row which the unique value in the text box came from. I also have a list box in the form which displays the items the user has selected. What I want to happen is that the user clicks an item from the list box (which is also unique in the table) and the text box instead displays it's information using this as the reference. At the moment the text box is being controlled with DLookup running the above query.
 
So change the DLookUp in both the ComboBox AfterUpdate and ListBox On Click.. Does that help? Something like..
Code:
Private Sub comboBoxName_AfterUpdate()
    Me.unBoundTextBox = DLookUp("theFieldName", "theTableName", "someField = '" & Me.comboBoxName & "'")
End Sub

Private Sub listBoxName_Click()
    Me.unBoundTextBox = DLookUp("theFieldName", "theTableName", "someField = '" & Me.listBoxName & "'")
End Sub
 
It is no difference between combo boxes and list boxes if you select a SINGLE item.
But, IF you have a list box that allow multiple items selection, AND wish that the query show a selection based on selected items you need to write an external function that return the WHERE clause for the query, and to apply this function from the Criteria row of the query.
 

Users who are viewing this thread

Back
Top Bottom