Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Access list box row source

Posted on 2013-01-30
3
Medium Priority
?
488 Views
Last Modified: 2013-02-19
I have a list box on a form and under its row source i want to filter based on the value of a combo box. Is this possible?

I have the code

select * from table where [field] = [forms]![frm_main]![cbo_search] but i get an error message

where am i going wrong? I dont want to use VBA coding if poss
0
Comment
Question by:CaptainGiblets
  • 2
3 Comments
 
LVL 49

Expert Comment

by:Dale Fye
ID: 38834883
What error message are you getting?

If the value in the combo is text, try something like the following in the AfterUpdate of the first combo, and in the Form_Current event (used to make sure that records that already have a value in the first combo have the right set of values in the 2nd).

Private Sub combo1_AfterUpdate

    me.Combo2.RowSource = "SELECT * FROM yourTable " _
                                              & "WHERE [Field] = '" & me.combo1 & "'"

End Sub

Note the embedded single quotes before and after the reference to combo1 (cbo_Search).
0
 
LVL 6

Author Comment

by:CaptainGiblets
ID: 38834895
i want to put the lookup in the row source of the list box if possible

so i have the combo box with values 1 and 2 that people can select and a default value of 1. if i put in what i said above it says incorrect syntax near !

If i put in quotes i get Invalid column Name '[forms]![frm_main]![cbo_search] '

If i put in quotes and & symbol i get Invalid column Name ' & [forms]![frm_main]![cbo_search] &'
0
 
LVL 49

Accepted Solution

by:
Dale Fye earned 2000 total points
ID: 38834938
Where are you putting this?

Does the syntax work if you simply put it in a query?  Remove the rowsource from the list, open your form, select the value from the combo, then create a query and paste in the syntax you used previously with:

Forms!frm_Main.cbo_Search

Note the dot between the form and the control, instead of a bang.

Does the query work?  If so, Save the query and make the rowsource of the listbox the name of the query.  Then change the code in the AfterUpdate event of the combo to something like:

me.listControlName.Requery
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question