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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Assigning SQL select query to a variable

Status
Not open for further replies.

neillovell

Programmer
Aug 27, 2002
560
GB
In VBA how can I assign the value of a query to a variable?
I've tried
SQL = "SELECT TotalPoints FROM PlayerTable WHERE ID=123"
Points = DatabaseConnection.Execute SQL
MsgBox TotalPoints

but the Points = line is erroring with "syntax Error" - how can I do this?
 

hello

a silly question but are you querying a SQL database or a table in access.

I'm guessing SQL - but must check first..
Jo
 
Create a saved query called qryTotalPoints. Copy and paste your SQL code into the SQL window:

Dim lngPoints as Long
lngPoints = DMax("TotalPoints", "qryTotalPoints")
MsgBox lngPoints


Post back with any questions.

Bob Scriver
Want the best answers? See FAQ181-2886
Nobody believes the official spokesman... but everybody trusts an unidentified source.
Author, Bagdad Bob???

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top