Run query to feed combo box

A

Alejandro

Hello there,

I have two combo boxes in a form and I would like the second box to be
populated based on a query run with code. So the user will select an option
in the first combo box and based on the selection a DoCmd.RunSQL command will
be run in the After Update event of that first box. I would like the result
of that query (whose output is a 1-column list of records) to be shown in the
second combo box.

Thanks in advance,

Alejandro.
 
M

Marshall Barton

Alejandro said:
I have two combo boxes in a form and I would like the second box to be
populated based on a query run with code. So the user will select an option
in the first combo box and based on the selection a DoCmd.RunSQL command will
be run in the After Update event of that first box. I would like the result
of that query (whose output is a 1-column list of records) to be shown in the
second combo box.


RunSQL is only useful for Action queries, so I don't see how
that idea can work. I think all you need to do is assign
the query name or SQL statement to the second combo box's
RowSource peoperty.
 
J

John W. Vinson

Hello there,

I have two combo boxes in a form and I would like the second box to be
populated based on a query run with code. So the user will select an option
in the first combo box and based on the selection a DoCmd.RunSQL command will
be run in the After Update event of that first box. I would like the result
of that query (whose output is a 1-column list of records) to be shown in the
second combo box.

Thanks in advance,

Alejandro.

There is no need to *run* the query using RunSQL or the .Execute method.
Simply set the combo box's RowSource property to the SQL string.

In fact, it's probably not necessary to do even that; you can base the second
combo box on a Query referencing the first combo box as a criterion:

=Forms!YourFormName!FirstComboName

and Requery the second combo in the AfterUpdate event of the first.
 

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