Query retrieving criteria from combo box on form

G

Guest

I can't figure out what I am doing wrong... I want the query criteria to be
defined by a combo box in the form. The user will select the criteria on the
combo box, then click a button to run the query, however the query keeps
coming up blank.

[Forms]![UserReview]![Staff] is what I have entered in the criteria for the
field in the query. If I simply type in "casbds1" as the criteria, which is
one of the choices in the combo box, it returns with the data I want, but I
just can't get it to work with the combo box. Any ideas what I am doing wrong?
 
J

Jeff Boyce

Perhaps what is actually in (the first column of) the combobox is NOT what
your query needs to see...

(... this may seem unrelated, but ...)
Is there any chance the field in question is defined in the underlying table
as a "lookup" data type? If so, you need to remember that what is stored in
that field and what is displayed in that field don't match. This can
seriously mess with your use of criteria in queries.

Regards

Jeff Boyce
<Office/Access MVP>
 
G

Guest

While the form is running, select a value in the combo, open the Immidiate
window (press Ctrl+G), type in
?Forms![UserReview]![Staff]
And press enter
Check what value is returned, it could be that the combo is bounded to a
different field in the rowsource, and it returnng the Id instead of
description
 
T

Tom Ellison

Dear Belly:

It might be useful for you to see what value the combo box is returning to
the query. Put the [Forms]![UserReview]![Staff] in the select list and it
will show that value in every row returned by the query. This may give you
a good clue.

Besides what Jeff offered, I'd also suggest you start naming your controls
with prefixes (as very many do) or with suffixes (as I do) that show what
kind of control it is. That is, instead of naming this control [Staff] you
could name it Staffcbo (cbo being the common designation for combo box).
Otherwise, if the form's recordsource has a column named Staff the Access
"name resolution" software may return the first value for "Staff" it finds,
and that might not be the "value" of the control, but of something else.
Uniqueness of naming is very, very important (no, make that "essential")
when working in an object oriented environment.

Please let me know if this helped, and if I can be of any other assistance.
Oh, and you might give me just a first name by which I can refer to you. We
try to keep things friendly here, and actually do make friends (and
hopefully not too many enemies) in here.

Tom Ellison
 
M

Mekinnik via AccessMonster.com

I also am having similar issues too, however I cannot figure out what code to
use in the after update event to show the what has been chosen from the combo
box.I have been trying different things and cannot get any to work.
 
T

Tom Ellison

Dear Mekinnik:

I'm not too clear what this situation of your is. You may want to start
with a SELECT query and have it tell you what values it is getting from your
controls. After you get some diagnostics and figure out what is wrong, work
you way up to more complex queries.

Tom Ellison
 

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