473,714 Members | 2,562 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to run sum() Function in VB6?

neo008
85 New Member
Hi All,

How to run sum() Function in VB6?

Adodc1.recordso urce="select sum(quantity) from purchase"
adodc1.refresh

1.) but how to retrieve result in desired text box like i took- AvailabeQuantit y.Text

somewhere i read that query is like "Select sum(quantity) as SumOfQuantity from purchase"

2.) in above statement what is "as SumOfQuantity"

can you please help me

NE☼
Jun 6 '07 #1
13 23114
ansumansahu
149 New Member
Hi All,

How to run sum() Function in VB6?

Adodc1.recordso urce="select sum(quantity) from purchase"
adodc1.refresh

1.) but how to retrieve result in desired text box like i took- AvailabeQuantit y.Text

somewhere i read that query is like "Select sum(quantity) as SumOfQuantity from purchase"

2.) in above statement what is "as SumOfQuantity"

can you please help me

NE☼
Hi ,

when you execute this query the quantity will be populated in the column named SumOfQuantity

-ansuman sahu
Jun 6 '07 #2
cmrhema
375 Contributor
Hi All,

How to run sum() Function in VB6?

Adodc1.recordso urce="select sum(quantity) from purchase"
adodc1.refresh

1.) but how to retrieve result in desired text box like i took- AvailabeQuantit y.Text

somewhere i read that query is like "Select sum(quantity) as SumOfQuantity from purchase"

2.) in above statement what is "as SumOfQuantity"

can you please help me

NE☼
I am not sure about adodc control but if you can change to adodb connection then put down the code as below.
Also remove adodc and
add reference Microsoft Active X Data objects 2.0 library by clicking on Project--References
Now the code
Expand|Select|Wrap|Line Numbers
  1. Dim MyCon As New ADODB.Connection
  2. Dim Myrs As New ADODB.Recordset
  3. Dim sConnect As String
  4.  
  5.  
  6. sConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  7.                        "Data Source=" & _
  8.                         App.Path & "emp.mdb"
  9. 'Replace emp with your file name
  10. MyCon.Open sConnect
  11. Myrs.Open "select sum(quantity) from purchase", MyCon, adOpenDynamic, adLockPessimistic
  12. text1.text=Myrs.Fields(0)
  13. Myrs.Close
  14. MyCon.Close
it will display the result.

as far as as "SumOfQuant ity" it should be used in sql query statement in sql not in visual basic.
Jun 6 '07 #3
neo008
85 New Member
Thank you Sahu, Thank you Cmrehma,

I have total 4 fields in my 'Purchase' table -(product_id, product_name, quantity, price)

what should be code for sum(quantity) if i use Adodc connection.

i have tried --
adodc1.recordso urce="select sum(quantity) from purchase"
adodc1.refresh

now how to get result in a text box????????

I want to retrieve data into a text box. THIS IS WHAT I WANT

as you said Sahu, SumOfQuantity is column in which my result will be populated. so how a result will go to database table? moreover in the form of column?

as you said cmrehma, forgive me if i misspelt you,
you said ---------->adodc1.fields( 0)
but i dont find any method with adodc named "Fields" so I got an error.

can you please sort out my need.

NE☼
Jun 6 '07 #4
cmrhema
375 Contributor
Thank you Sahu, Thank you Cmrehma,

I have total 4 fields in my 'Purchase' table -(product_id, product_name, quantity, price)

what should be code for sum(quantity) if i use Adodc connection.

i have tried --
adodc1.recordso urce="select sum(quantity) from purchase"
adodc1.refresh

now how to get result in a text box????????

I want to retrieve data into a text box. THIS IS WHAT I WANT

as you said Sahu, SumOfQuantity is column in which my result will be populated. so how a result will go to database table? moreover in the form of column?

as you said cmrehma, forgive me if i misspelt you,
you said ---------->adodc1.fields( 0)
but i dont find any method with adodc named "Fields" so I got an error.

can you please sort out my need.

NE☼
Check out the new reply. I replaced the old one
Jun 6 '07 #5
neo008
85 New Member
Check out the new reply. I replaced the old one
Thanx Cmrhema, I just check it out.
Jun 6 '07 #6
neo008
85 New Member
I am not sure about adodc control but if you can change to adodb connection then put down the code as below.
Also remove adodc and
add reference Microsoft Active X Data objects 2.0 library by clicking on Project--References
Now the code
Expand|Select|Wrap|Line Numbers
  1. Dim MyCon As New ADODB.Connection
  2. Dim Myrs As New ADODB.Recordset
  3. Dim sConnect As String
  4.  
  5.  
  6. sConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  7.                        "Data Source=" & _
  8.                         App.Path & "emp.mdb"
  9. 'Replace emp with your file name
  10. MyCon.Open sConnect
  11. Myrs.Open "select sum(quantity) from purchase", MyCon, adOpenDynamic, adLockPessimistic
  12. text1.text=Myrs.Fields(0)
  13. Myrs.Close
  14. MyCon.Close
it will display the result.

as far as as "SumOfQuant ity" it should be used in sql query statement in sql not in visual basic.

Thanx for your interest, I am new to VB and not used Adodb before.
I have used adodc in entier project.

Is it possible to change Adodc connection to Adodb for a piece of code
(As you are suggesting me)
If it is so, are you sure it would not affect rest of my project.


Cmrhema, I really appreciate your interest.
Even if you can't tell me about Adodc I thank you by heart.

NE☼
Jun 6 '07 #7
neo008
85 New Member
I am not sure about adodc control but if you can change to adodb connection then put down the code as below.
Also remove adodc and
add reference Microsoft Active X Data objects 2.0 library by clicking on Project--References
Now the code
Expand|Select|Wrap|Line Numbers
  1. Dim MyCon As New ADODB.Connection
  2. Dim Myrs As New ADODB.Recordset
  3. Dim sConnect As String
  4.  
  5.  
  6. sConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  7.                        "Data Source=" & _
  8.                         App.Path & "emp.mdb"
  9. 'Replace emp with your file name
  10. MyCon.Open sConnect
  11. Myrs.Open "select sum(quantity) from purchase", MyCon, adOpenDynamic, adLockPessimistic
  12. text1.text=Myrs.Fields(0)
  13. Myrs.Close
  14. MyCon.Close
it will display the result.

as far as as "SumOfQuant ity" it should be used in sql query statement in sql not in visual basic.
Hi Cmrhema, My reply had not been posted last time so I'm writing again.

I am very new to VB and never used Adodb before.
I have used Adodc only in my entire project.

Is it possible to use Adodb for a piece of code without affecting the rest of the project having code for Adodc.?

I appreciate your interest. Even if you cant tell me much about Adodc, I thank you by heart for your support.

NE☼
Jun 6 '07 #8
cmrhema
375 Contributor
Thanx for your interest, I am new to VB and not used Adodb before.
I have used adodc in entier project.

Is it possible to change Adodc connection to Adodb for a piece of code
(As you are suggesting me)
If it is so, are you sure it would not affect rest of my project.


Cmrhema, I really appreciate your interest.
Even if you can't tell me about Adodc I thank you by heart.

NE☼
Usually it is not desirable to put both into one project. But because you have no choice go for it.
Jun 6 '07 #9
neo008
85 New Member
Check out the new reply. I replaced the old one
I am replying you 3rd time.

I dont know wht's the problem behind this but...

Actually Cmrhema, I have never used Adodb and my entire project is having Adodc connection.

So is it possible to use Adodb for a piece of code without affecting the Adodc code of rest of the project.

NE☼
Jun 6 '07 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

4
5611
by: Ben | last post by:
Hi all, I'm trying to figure out how how complex map, filter and reduce work based on the following piece of code from http://www-106.ibm.com/developerworks/linux/library/l-prog.html : bigmuls = lambda xs,ys: filter(lambda (x,y):x*y > 25, combine(xs,ys)) combine = lambda xs,ys: map(None, xs*len(ys), dupelms(ys,len(xs))) dupelms = lambda lst,n: reduce(lambda s,t:s+t, map(lambda l,n=n: *n, lst))
4
79482
by: gooday | last post by:
Table test2 has multiple amounts for each account, I would like to sum the amounts for the same account and use the result to update the variable 'tot_amount' in table test1. But SQL does not allow me to use sum function in update. Is there any other way to do this? Thanks. update test1 set tot_amount=sum(b.amount) from test1 as a join test2 as b on a.acc_no=b.acc_no
6
4080
by: un[real] | last post by:
Like I said in the title, I have to calculate the sum of the numbers of an interger with a recursive fonction. Exemple: n=1255, sum= 1 + 2 + 5 + 5= 13 Do I have to use a string on can I use a simple cin ?? Thanks for your help !! And sorry for my english :)
2
15063
by: Scott Cannon | last post by:
I am trying to query 3 tables all related by Clinet_ID. The Clients table, Monthly_Expenses table and Monthly_Income table. Each client can have 0>M instances of expenses, past due expenses, and income so I am using the SUM aggregate function to get the totals for the Monthly_Epenses.Amount, Monthly_Expenses.Past_Due_Amount, and Monthly_Income.Amount. Then problem I am having and cannot seem to resolve is that the Monthly_Income is...
52
3957
by: Paddy | last post by:
I was browsing the Voidspace blog item on "Flattening Lists", and followed up on the use of sum to do the flattening. A solution was: I would not have thought of using sum in this way. When I did help(sum) the docstring was very number-centric: It went further, and precluded its use on strings:
2
7601
by: dwasbig9 | last post by:
Hi Group (fairly limited knowledge of Access and almost none of Access VBA. Using Access 2003). I need to sum time, I've found through the groups archive an sql extract that led me to this SELECT Format(Sum(Table2.time),"Short Time") AS SumOftime FROM Table2; Which works fine but the article also said I would need a Function to
2
1899
n8kindt
by: n8kindt | last post by:
i don't know what to do about this one. there are some very strange things going on. i have a continuous form with a bound textbox and a bound toggle button. the textbox is named "Payment" and the toggle is named "Apply." i want to have a textbox in the footer (named TotalPayment) that calculates the sum of whatever is in the textbox, provided that the bound toggle button is set to True. i created a function for this purpose. here it is: ...
54
8342
by: bearophileHUGS | last post by:
Empty Python lists don't know the type of the items it will contain, so this sounds strange: 0 Because that may be an empty sequence of someobject: 0 In a statically typed language in that situation you may answer the
7
3504
by: cnb | last post by:
This must be because of implementation right? Shouldn't reduce be faster since it iterates once over the list? doesnt sum first construct the list then sum it? ----------------------- reduce with named function: 37.9864357062 reduce with nested, named function: 39.4710288598 reduce with lambda: 39.2463927678 sum comprehension: 25.9530121845
6
2893
by: azegurb | last post by:
Hello, I have one question again i created one table again and in this table i added some another options for ex at the previous table there were only one problem sum of the dynamically added rows in this beside sum i need to sum of the tax for ex: in column1 i added 300 and into 2-nd column i Chose 10% i would like when i chose from drop down box 10% Let in the 2-nd column appear 10% of the value which i addee first column for ex...
0
8796
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9307
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9071
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
7946
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6627
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5943
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4715
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2514
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2105
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.