Solved

Access list box row source

Posted on 2013-01-30
3
473 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 47

Expert Comment

by:Dale Fye (Access MVP)
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 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
I see at least one EE question a week that pertains to using temporary tables in MS Access.  But surprisingly, I was unable to find a single article devoted solely to this topic. I don’t intend to describe all of the uses of temporary tables in t…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

861 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now