WUGNET, the Windows User Group Network
Your Complete Resource Center for "The Best" in Shareware, Computing Tips and Support, Windows Industry News... and much more!
Home Forums Shareware Windows Tips Hot Offers FREE Newsletters Arcade Contact Us About Partners
Search WUGNET: RSS Feeds RSS Feeds Advertise with WUGNET    |    Shareware eBooks
HomeHome FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Add Two Values Within An SQL Statement

 
   Home -> Office other -> Getting Started RSS
Next:  stLinkCriteria  
Author Message
iain

External


Since: Aug 24, 2009
Posts: 9



(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
Back to top
Login to vote
John Spencer

External


Since: Apr 09, 2008
Posts: 750



(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
Back to top
Login to vote
iain

External


Since: Aug 24, 2009
Posts: 9



(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
>
Back to top
Login to vote
Display posts from previous:   
       Home -> Office other -> Getting Started 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
Categories:
 Windows XP
 Windows Vista
 Windows Other
 Office
  Office Other
 Security
  • Home |
  • Shareware |
  • Windows Tips |
  • Hot Offers |
  • FREE Newsletters |
  • Arcade |
  • Forums |
  • eBooks |
  • About WUGNET |
  • Partners |
  • Contact

  • WUGNET Privacy Policy |
  • Link to WUGNET |
  • IT Support