referring to a totals query on a form

B

bicyclops

If I create a totals query, or one that uses the Top 1 value, or basically
any query that returns just one row, is it possible to refer to a field value
in it from a control on a form without using the domain aggregate functions?
It seems like there must be an easier way to get that value than using
dlookup. But just pointing to the field from a control produces a #Name error.

Thanks in advance.
 
M

Marshall Barton

bicyclops said:
If I create a totals query, or one that uses the Top 1 value, or basically
any query that returns just one row, is it possible to refer to a field value
in it from a control on a form without using the domain aggregate functions?
It seems like there must be an easier way to get that value than using
dlookup. But just pointing to the field from a control produces a #Name error.


Well, there are other ways to do that, but a DLookup to your
query is the easiest way to get a single field's value.

If your one row query returns multiple fields, then you
would get better perfomance by using a VBA procedure to open
a recordset on the query and then copying the field values
to their related text boxes.
 
O

Ofer

Another option is to add that query to the recordsource of the form, without
linking the table to the query, then add the field, then you can bound the
field in the form to this field. The problem is that you wont be able to
update the data.

So I would keep using the dlookup without criteria, if there is only one
record
=dlookup("FieldName","TableName")
 
Top