Change a Listbox recordsource with the use of Option Buttons

spnz

Registered User.
Local time
Today, 00:46
Joined
Feb 28, 2005
Messages
84
Good afternoon

I have been helped out so many times in the past here I thought I would try my luck again.

Is it possible with the use of option buttons to change the row source of a listbox?
I want to use the listbox for a search criteria and thought it might be easier to have 1 listbox been updated from the choices made using a group of buttons.
I would like like the row source to be based on different tables maybe I might need to use queries.


Can anyone point me in the right direction?
 
Hi,

something like:

Code:
Private Sub button1_AfterUpdate()

     list1.rowsource = something
    
End Sub

Or if you're using an optiongroup:

Code:
Private Sub OptionGroup1_AfterUpdate()

     if OptionGroup1.value = 1 then
           list1.rowsource = something
     elseif OptionGroup1.value = 2 then
           etc.....
    
End Sub

Hope that helps.
 
Hi Lucas

Yes I am using an option group

how do I get the rowsource to look at the correct table?

e.g I have a table called tblIngredients and a field called Ingredients within that table.

would I use


Private Sub OptionGroup1_AfterUpdate()

if OptionGroup1.value = 1 then
list1.rowsource = "tblIngredients.Ingredient"


End Sub



Is that correct?
 
If you want to show a list of all available criteria then you would need a query as the rowsource. Set the rowsource type to query/table (in the property sheet of the listbox), and then the code would go something like this:

Code:
Private Sub OptionGroup1_AfterUpdate()

if OptionGroup1.value = 1 then
list1.rowsource = "SELECT DISTINCT tblIngredients.Ingredient FROM tblIngredients;"
Elseif...etc

End Sub
 
Try this

if OptionGroup1.value = 1 then
Me.List1.RowSource = "SELECT [tblIngredients].[Ingredient]" "From tblIngredients "
 
Great thanks both of you for your suggestions.

Working great now!!!

Thanks again!
 
or, create and save a query and,

if OptionGroup1.value = 1 then
Me.List1.RowSource = "qryNameOfYourQuery"

include the PK in the query but hide that row in the list.
 

Users who are viewing this thread

Back
Top Bottom