Assign Query Result to variable

  • Thread starter Thread starter Sean Timmons
  • Start date Start date
S

Sean Timmons

I'm running a query to retrieve an e-mail address based on an employee name.
Easy enough.

Now, I'm trying to get the result of this query assigned to a variable to I
can use it in my SendObject command, and I can't figure it out.

I could just cheat and include the e-mail in my form as an invisible field,
but that's not very sporting...
 
You can use a DLookup:

var = DLookup("fieldName", "queryName", true)


You can also open a recordet, and read the first field of the first record.
Here, with a firehose recordset:

var = CurrentProject.Connection.Execute("queryName").Fields(0).Value

You can use a query and base your form on the query, rather than on a table,
directly.


Vanderghast, Access MVP
 
That was absolutely perfect! The DLookup did all I needed! I can sleep
tonight! Thank you!
 
Back
Top