(Msg. 1) Posted: Sat Sep 26, 2009 9:35 am
Post subject: Add Two Values Within An SQL Statement Archived from groups: microsoft>public>access>gettingstarted (more info?)
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
(Msg. 2) Posted: Sat Sep 26, 2009 1:27 pm
Post subject: Re: Add Two Values Within An SQL Statement [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
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
(Msg. 3) Posted: Sun Sep 27, 2009 9:15 am
Post subject: Re: Add Two Values Within An SQL Statement [Login to view extended thread Info.] Archived from groups: per prev. post (more info?)
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
>
All times are: Eastern Time (US & Canada) (change)
Page 1 of 1
You can post new topics in this forum You can reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum