 |
| View previous topic :: View next topic |
| Author |
Message |
j.harrower Newbie
Joined: 02 May 2006 Posts: 1
|
Posted: May 2nd, 2006 09:36 PM Post subject: sum function |
|
|
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 |
|
i_am_doofus Regular
Joined: 04 Jun 2005 Posts: 57
|
Posted: May 3rd, 2006 07:24 AM Post subject: |
|
|
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 |
|
|
|
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
|
|