If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Add Two Values Within An SQL Statement
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 |
#2
|
|||
|
|||
Add Two Values Within An SQL Statement
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 iain wrote: 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 |
#3
|
|||
|
|||
Add Two Values Within An SQL Statement
Thank you John
"John Spencer" wrote: 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 iain wrote: 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 |
Thread Tools | |
Display Modes | |
|
|