Assign Query Result to variable

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...
 
M

Michel Walsh

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
 
S

Sean Timmons

That was absolutely perfect! The DLookup did all I needed! I can sleep
tonight! Thank you!
 

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