Solved

Access list box row source

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

Independent Software Vendors: 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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

679 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