Retrieving a single value from a table

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

Guest

Is there a simple way in VBA to retrieve a single value from a table?

Suppose I have a table T with two fields, K (for key) and V (for value). I
want to execute a query:

SELECT V from T WHERE K = "something"

and return the value into a variable. It would be as though Docmd.RunSQL
was able to return a value.

I know how to create a recordset, open it, read a record and close the
recordset. I just wondered if there was an easier way.
 
The aggregate functions come to mind

DLookup("V","T","K=""Something"")

DLookup, DCount, DFirst, DLast, DSum, DAvg are all functions that you can
call in your VBA.

--
John Spencer
Access MVP 2002-2005, 2007
Center for Health Program Development and Management
University of Maryland Baltimore County
..
 
Back
Top