Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Best way to use SQL statements in VB code

Status
Not open for further replies.

Jorgandr

Programmer
May 10, 2002
58
US
What is the best way to include an SQL statement in my VB Code and then assign the value to a variable? For example, when my form opens I would like to be able to select the max value from a table and then store it in a Global variable??
 
The easiest way would be to use the dmax function

variable = dmax("field","table","any criteria")

the best way would be to use a recordset

'Dao
dim strsql as string
dim rst as recordset
strsql = "select max(field) from table where criteria"
set rst=currentdb.openrecordset(strsql)
rst.movefirst
variable = rst.field(0)
rst.close
set rst = nothing
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top