A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » New Users
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Add Two Values Within An SQL Statement



 
 
Thread Tools Display Modes
  #1  
Old September 26th, 2009, 05:35 PM posted to microsoft.public.access.gettingstarted
Iain
external usenet poster
 
Posts: 112
Default 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  
Old September 26th, 2009, 06:27 PM posted to microsoft.public.access.gettingstarted
John Spencer
external usenet poster
 
Posts: 7,815
Default 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  
Old September 27th, 2009, 05:15 PM posted to microsoft.public.access.gettingstarted
Iain
external usenet poster
 
Posts: 112
Default 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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 04:36 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.