Log inUsernamePassword
Log me on automatically each visit    
Register
Register
Log in to check your private messages
Log in to check your private messages
Visual Basic Forum for Visual Basic Programmers VB Forum Index » General

Post new topic   Reply to topic
sum function
View previous topic :: View next topic  
Author Message
j.harrower
Newbie


Joined: 02 May 2006
Posts: 1

PostPosted: May 2nd, 2006 09:36 PM    Post subject: sum function Reply with quote

hey guys, desperatly hope someone can help me!

i got a simple access database made up, two tables, one of the columns in the table is called amounts and contains a few rows of integers, (45, 15, 23, etc), i have made a screen in vb6 that contains a textbox and you enter details into the textbox and then save it through the screen to the database, on another vb 6 screen i want to display the sum (total amount) of the amounts column in a textbox, how do i do that? all the info i can find contains loads of sql stuff, i'm a newbie, i dont understand!
Back to top
View user's profile Send private message
i_am_doofus
Regular


Joined: 04 Jun 2005
Posts: 57

PostPosted: May 3rd, 2006 07:24 AM    Post subject: Reply with quote

You can either have SQL sum the numbers for you with its built in function that was designed for that purpose [easiest way to go] or you can retrieve all the numbers from the database using SQL and then total them yourself in VB.

For the first way:

Dim strSQL As String
strSQL = Select Sum(Amount) From your_table_name

When you execute this SQL statement it will return the total of the figures in the Amount column of your table. You then just assign this recordset value to your TextBox's .Text property.

For the second way:

Dim strSQL As String
strSQL = Select Amount From your_table_name

When you execute this SQL statement it will return the individual values stored in the Amount column of your database table. You will then need loop through the recordset, add the individual values together and then assign the total to your TextBox's .Text property.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Visual Basic Forum for Visual Basic Programmers VB Forum Index » General All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot 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


Visual Basic Forum runs phpBB | Forum Template © iOptional
VB Resources | SSL | Visual Basic