Display result of query in text box on form

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

How do I code a button on a form to run a query and display the results in a
text box (on the current form)?

thank you!
 
Is this a bound form? You could bind the form to the query (set it's Record
Source property to the name of the query) and then set th text box's Control
Source to the name of the field. Under the button's event sub put:

Me.Requery

HTH,
Barry
 
How do I code a button on a form to run a query and display the results in a
text box (on the current form)?

thank you!

How many records are returned by the query?
If just one all you need to display one field is:
[ControlName] = DLookUp("[FieldName]","QueryName")

If more than one record is returned, you can display one field, as
above, but you must add criteria (Where clause) to the DLookUp to get
the correct record.

If you need to see all the records, create a form to display them in.
Use the query as record source.
Then code a command button on a form:
DoCmd.OpenForm "FormName"
 
You did not specify what was your task. May be my experience will be helpful
to you:
When I want to find some records (one or more) and I want the results to be
displayed in the same form, I make a button with a Macro:

Action:Apply Filter
Condition: [T_SPENT]![PREQ No] Like ("*"+[Enter PREQ Number]+"*").

In this case the dialogue window will open and ask me to "Enter PREQ
Number", and the results will be matching any part of the field to what you
entered.

You may change your condition to some unvariable, like:

Action:Apply Filter
Condition: [T_SPENT]![PREQ No] = "4"


Regards, Lana
 
Thank you, Fred. This was exactly what I needed!!!

fredg said:
How do I code a button on a form to run a query and display the results in a
text box (on the current form)?

thank you!

How many records are returned by the query?
If just one all you need to display one field is:
[ControlName] = DLookUp("[FieldName]","QueryName")

If more than one record is returned, you can display one field, as
above, but you must add criteria (Where clause) to the DLookUp to get
the correct record.

If you need to see all the records, create a form to display them in.
Use the query as record source.
Then code a command button on a form:
DoCmd.OpenForm "FormName"
 
If i want to display the results of various queries on the same form, would
the same principle apply?

Lana said:
You did not specify what was your task. May be my experience will be helpful
to you:
When I want to find some records (one or more) and I want the results to be
displayed in the same form, I make a button with a Macro:

Action:Apply Filter
Condition: [T_SPENT]![PREQ No] Like ("*"+[Enter PREQ Number]+"*").

In this case the dialogue window will open and ask me to "Enter PREQ
Number", and the results will be matching any part of the field to what you
entered.

You may change your condition to some unvariable, like:

Action:Apply Filter
Condition: [T_SPENT]![PREQ No] = "4"


Regards, Lana


eacollie said:
How do I code a button on a form to run a query and display the results in a
text box (on the current form)?

thank you!
 
Back
Top