Display query results in a text box

G

Guest

I'm trying to get the results of a query to show up in a text box at the top
of a form. Actually, I just want one column of the query to appear there.
I've got the query working, and can get the result to display in a combo box
by entering "qryBaseline.Level" (query name.column name) as the Row Source.
But, since this is strictly informational for the user, I want it to appear
in a text box that I will then lock. Any ideas?

Thanks,
Tim
 
F

fredg via AccessMonster.com

You can only display one field of one record in a text control, not many
records.

If the query returns just one record, you can use, as the text control's
control source:
=DLookUp("[FieldName]","QueryName")

If the query returns many records, you can use criteria to limit the result
to just the one record wanted:
=DLookUp("[FieldName]","QueryName","[SomeField] = " & SomeValue)The above
assumes the criteria value is a Number datatype.
 
G

Guest

The query has 6 columns, but is set to only return one record. For the
control source of the text box I entered:

=DLookUp([Level],[qryBaseline])

Level is the name of the column I want displayed, and qryBaseline is the
name of the query. When I did this and opened the form, the text box
displayed: #Name?

Any idea what I'm doing wrong?
 
G

Guest

The query has 6 colums, but I set it to only return one record. I set the
control source of the text box to:

=DLookUp([Level],[qryBaseline])

Level is the name of the field I want displayed and qryBaseline is the name
of the query. When I opened the form to look at it, the text box displayed:
#Name?

Any ideas?
 
J

John Vinson

The query has 6 colums, but I set it to only return one record. I set the
control source of the text box to:

=DLookUp([Level],[qryBaseline])

Level is the name of the field I want displayed and qryBaseline is the name
of the query. When I opened the form to look at it, the text box displayed:
#Name?

The arguments to DLookUp need to be *text strings*, not objects or
fields:

DLookUp("[Level]", "[qryBaseline]")

will work.

John W. Vinson[MVP]
 
G

Guest

That did the trick, thanks so much!

Tim

John Vinson said:
The query has 6 colums, but I set it to only return one record. I set the
control source of the text box to:

=DLookUp([Level],[qryBaseline])

Level is the name of the field I want displayed and qryBaseline is the name
of the query. When I opened the form to look at it, the text box displayed:
#Name?

The arguments to DLookUp need to be *text strings*, not objects or
fields:

DLookUp("[Level]", "[qryBaseline]")

will work.

John W. Vinson[MVP]
 

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