Cmd Button Issue

J

James

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
 
F

fredg

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")
 
J

James

Ok so your saying I dont need the command button to
execute the query? if not how can I execute the query and
pull the result into my txt box?

Also in your post you posted this:

=DLookUp("[FieldName]","QueryName", "Some Criteria here if
needed")

What sort of criteria would I be putting in if I needed
it? plus would the above bit of "code" do what I am saying
above?

Many Thanks

James
-----Original Message-----
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.
.
 
J

Jams

Just another quick thought I have had...

Will the below code update its self whenever the cboboxes
values change?

Many Thanks

James
-----Original Message-----
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.
.
 
F

fredg

Just another quick thought I have had...

Will the below code update its self whenever the cboboxes
values change?

Many Thanks

James
-----Original Message-----
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.
 
J

James

Ok I will see if I can explain this in more detail...

I have a form where by I have 3 cboboxes on it...

These have the follwoing values:

cbo1 (Male,Female)
cbo2 (Q01,Q02....Q25)
cbo3 (True,False)

I have a query which calculates the percentage in the
database based on the values of them cboboxes.... so it
gets the percentage of the total number of records by how
many of the values in them cboboxes...

I would need my text box to pull up that percentage from
the query based on what is in the cboboxes.... So if they
change I would need the test box to be updated when all
the values have changed and maybe a calculate button
pressed?

IS this of more help?

Many Thanks for your time and effort

james
-----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.
.
 

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