Add Two Values Within An SQL Statement

I

iain

Does anyone know if it is possible to add two values together within an SQL
statement so that the total is inserted into the field in the table?

For example a counter in a For/Next Loop to a variable called Index.

Private Sub FileCount(Name as string, Index as long, Quantity as Integer)
Dim mySQL as String
Dim n as Integer
For n=0 to Quantity - 1
mySQL = "INSERT INTO myTable VALUES(Name, Index + n)"
Next n
End Sub
 
J

John Spencer

Dim Db as DAO.Database
Set Db = CurrentDb()

For n=0 to Quantity - 1
mySQL = "INSERT INTO myTable VALUES(""" & Name & """, " & Index + n & ")"
Db.Execute mySQL, dbFailOnError
Next n

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 
I

iain

Thank you John

John Spencer said:
Dim Db as DAO.Database
Set Db = CurrentDb()

For n=0 to Quantity - 1
mySQL = "INSERT INTO myTable VALUES(""" & Name & """, " & Index + n & ")"
Db.Execute mySQL, dbFailOnError
Next n

John Spencer
Access MVP 2002-2005, 2007-2009
The Hilltop Institute
University of Maryland Baltimore County
 

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