Solved

Access list box row source

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

743 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

13 Experts available now in Live!

Get 1:1 Help Now