Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Access list box row source

Posted on 2013-01-30
3
Medium Priority
?
487 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 48

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 48

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
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.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

715 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