-----Original Message-----
Just another quick thought I have had...
Will the below code update its self whenever the cboboxes
values change?
Many Thanks
James
-----Original Message-----
On Wed, 14 Apr 2004 04:06:32 -0700, James wrote:
Hello I have a command button which I want to run a query
and then put the result of the query (a percentage) into a
text box on my form. How do I achieve this?
Many Thanks
James
If you wish to show just one field from one record of
the
query, you
don't need the command button.
As control source in an unbound control on the form:
=DLookUp("[FieldName]","QueryName", "Some Criteria here if needed")
--
Fred
Please only reply to this newsgroup.
I do not reply to personal email.
.
What Combo Box?
Your original message was you wanted to get data from a query into a
TEXT box on your form. A text box can display just one field (or one
item) of information.
I responded with "If you wish to show just one field from one record
of the query, ..."
So it appears I don't quite follow exactly what it is you wish to do.
If you wish to show, for example, how many widgets were sold in June,
and your query was designed to give that answer, you do not have to
run the query itself. All you need do is write the DLookUp I gave you
(changing the field and table names to what yours are) in a Text
control's control source. Since I do not know what kind of data you
are trying to get, I do not know if you need to restrict your data to
any particular query record. It may be that your query returns just
one item of data and no criteria is needed.
If the query returns lot's of records, then you do need to restrict
the DLookUp to return just the one item. That's what the "Some
Criteria here if needed" referred to. If the query returned 12
records, one for each month of the year, and you wanted the number of
widgets sold in June, you would write:
= DLookUp("[WidgetsSold]","QueryName","[TheMonthName] = 'June'")
I would suggest you look in VBA help for the DLookUp() function and
also
Where Clause + Restrict data to a subset of records
The Where clause must be written differently for each of the different
datatypes.
Now if you wish to populate a Combo box with the fields of many
records, you cannot use DLookUp. It only returns 1 item, not many
items.
To fill a Combo Box with all the records of a query, make the query
the Row Source of the combo box.
--
Fred
Please only reply to this newsgroup.
I do not reply to personal email.
.