Populating a TextBox with the value from a query on startup

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

Guest

I want to have a textbox on a form populated with a query result when the
form opens up. How do I set this up?
 
I want to have a textbox on a form populated with a query result when the
form opens up. How do I set this up?

I take it the query is not the record source for the form.
If the query returns just one record, you can use a DLookUp.
As Control source of an Unbound control:

=DLookUp("[FieldName]","QueryName")

If the query returns more than one record, add a where clause to the
above.
See DLookUp in VBA help as well as
Where clause + Restrict data to a subset of records.

You can also use the same expression in the form's Load event (not
Open event) to populate an unbound control:

[ControlName] = DLookUp( etc. )
 
OnOpen do this using DLookup

txtBox = DLookup("fieldNameInTable", "tableName", "fieldName = value")

Last arguement is like the WHERE clause in a sql statement.

Hope this helps.
Andy G.
 
Back
Top