Add Two Values Within An SQL Statement

  • Thread starter Thread starter iain
  • Start date Start date
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
 
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
 
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
 
Back
Top