Passing value from combobox to query?

?

...

Some simple things can make big problems. I can not make combobox work as it
should. Please help.

I have two comboboxes on form. Choice in combobox 1 should be criteria for
filtering data in query (on which combobox 2 is based). What could be the
sintax for passing data to query in design view in field criteria, or in
SQL view? Is it possible to make it with some public variable, which value
would be used in query. What would look like syntax in field criteria for
calling that value?
Thanks in advance.

Best regards,
Stosic Dejan.
 
H

Housemate

Hi Stosic,

To have a combo box show a list based on another combo box try the
following:

Consider two combo boxes called cbx_one and cbx_two

in cbx_one under properties, under row source, enter your sql text as
normal to query one of your tables e.g.

SELECT [tbl_Demo].[ID], [tbl_Demo].[Forename] FROM tbl_Demo;

This basically says show the ID field and Name field from the Table
called Demo.....pretty straight forward.(Always make sure the ID is
included as this is used in the second combo box).


Then you need to create a query and insert the required fields that you
want to show in the second combo box remebering to include the ID
placed in the the first combo box [Hope this makes sense!].

Then in cbx_two under properties under row source, try the following:

SELECT [qry_Demo].[Surname] FROM qry_Demo WHERE
((([qry_Demo].[ID])=[Forms]![frm_Demo]![cbx_One])) ORDER BY
[qry_Demo].[Surname];


Just change all text in the [] brackets to what is relevant in your
database and all should work fine!!

Hope this makes sense and helps, it definately works! ;o)

Regards
Housemate
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top