473,320 Members | 1,817 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

How to run sum() Function in VB6?

neo008
85
Hi All,

How to run sum() Function in VB6?

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

1.) but how to retrieve result in desired text box like i took- AvailabeQuantity.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 22950
ansumansahu
149 100+
Hi All,

How to run sum() Function in VB6?

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

1.) but how to retrieve result in desired text box like i took- AvailabeQuantity.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 256MB
Hi All,

How to run sum() Function in VB6?

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

1.) but how to retrieve result in desired text box like i took- AvailabeQuantity.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 "SumOfQuantity" it should be used in sql query statement in sql not in visual basic.
Jun 6 '07 #3
neo008
85
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.recordsource="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 256MB
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.recordsource="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
Check out the new reply. I replaced the old one
Thanx Cmrhema, I just check it out.
Jun 6 '07 #6
neo008
85
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 "SumOfQuantity" 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
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 "SumOfQuantity" 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 256MB
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
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
cmrhema
375 256MB
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☼
lookup the previous replu
Jun 6 '07 #11
cmrhema
375 256MB
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☼
lookup the previous reply
Jun 6 '07 #12
neo008
85
Dear Cmrhema,

it's giving error message : "Not a valid file name."

I have put 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.                 sConnect = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
  6.                                        "Data Source=" & _
  7.                                         App.Path & "E:\Projects\Rishika Enterprises Project\Database\Rishika070601.mdb"
  8.                 'Replace emp with your file name
  9.                 MyCon.Open sConnect
  10.                 Myrs.Open "select sum(quantity) from purchase", MyCon, adOpenDynamic, adLockPessimistic
  11.                 Text1.Text = Myrs.Fields(0)
  12.                 Myrs.Close
  13.                 MyCon.Close
When I put only Database file name "Rishika070601.mdb" it says can not find file E:\VBProjects\InventoryRishika07061.mdb
Jun 6 '07 #13
neo008
85
Hi Cmrhema,

It's working now.

Thanx a lot. Actually I'm from embedded side and new to VB that's why troubled you so much.

I appreciate your helping nature.

-NE☼
Jun 6 '07 #14

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

Similar topics

4
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 : ...
4
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...
6
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...
2
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...
52
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...
2
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 ...
2
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...
54
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...
7
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...
6
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...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.