473,413 Members | 2,053 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,413 software developers and data experts.

Sum Of A Field In Vb6.0

I have created a project where I created a form (scm.frm). In this form I put a caption (label9). This caption will show the total amount in a database field. It is working properly, example if I want to know the total transaction in November month, it is showing properly. If this month has transaction NIL, it also shows. But when I want to see the transacton NIL month before I saw a total amount transacted month, it doesn't change the value in the form.

More specifically, I have database named A, its fields are Month, Year, Amount.
November month Total Amount=10000
December " =20000
January " =00000
I select November month with 2007 yr, it is showing 10000. Again I select December 2007, it is showing 20000, properly. But if I select January 2007, it is showing 20000 (the previous data).
I am giving you code...

I have declared in module...
Global con as new ADODB.connection

General declaration------
Expand|Select|Wrap|Line Numbers
  1. Dim data1 As New ADODB.Command
  2. Dim rs As New ADODB.Recordset
  3. Dim subs As String
  4. Dim subs1 As String
clik a command button()
Expand|Select|Wrap|Line Numbers
  1. On Error Resume Next
  2. data1.ActiveConnection = con
  3. data1.CommandText = "select sum(amunt) from amn where mon & yr & schm='" & (Combo1.Text) & "' & '" & (Text1.Text) & "''"
  4. rs.Open data1, , adOpenDynamic, adLockReadOnly
  5. If Not rs.EOF Then
  6.   subs = rs.Fields(0)  /data field
  7.   subs = rs.Fields(1)  / ''
  8.   subs = rs.Fields(2)
  9.   subs = rs.Fields(3)
  10.   Label9.Caption = subs
  11. End If
  12. rs.Close
Please help me.
Nov 18 '07 #1
5 5790
Killer42
8,435 Expert 8TB
If you're going to post code here, you really should paste it directly so that we know we're looking at what actually executes. We can't trust the code you have posted here, because it has things which obviously wouldn't work. For example:
  • Field name amunt in the SQL doesn't match what you told us.
  • The variable subs is overwritten multiple times - doesn't make any sense.
  • Does that "where mon & yr ..." in the SQL work? I'm not familiar with the syntax.
Nov 18 '07 #2
I am clearingly you properly.

The backend of my project is MS Access... Where a table named amn is being created, where its fields name are amunt, mon, yr, schm.
In this VB form, I have to select the Month(i.e. mon), Year(i.e yr ), Scheme(i.e schm).

I'm sorry, the sub will be used only 1 time i.e subs = rs.Fields(0).

This above code is working properly but when I want to see the transacted less month total amount after a transacted amount displays, it did not change.

Expand|Select|Wrap|Line Numbers
  1. On Error Resume Next
  2. data1.ActiveConnection = con
  3. data1.CommandText = "select sum(amunt) from amn where mon & yr & schm='" & (Combo1.Text) & "' & '" & (Text1.Text) & "''"
  4. rs.Open data1, , adOpenDynamic, adLockReadOnly
  5. If Not rs.EOF Then
  6.   subs = rs.Fields(0)  /data field
  7.   Label9.Caption = subs
  8. End If
  9. rs.Close
Nov 19 '07 #3
Killer42
8,435 Expert 8TB
I am clearingly you properly.
Um... you are what?!


Anyway, it sounds as though for the months that are giving you trouble, there simply aren't any records. So one of two things is probably happening. Either the On Error Resume Next is skipping over part of your code (test this by commenting it out) or the If Not rs.EOF Then test is not firing because EOF is True.
Nov 19 '07 #4
It is working. I have added a code before rs.close. The code is.
subs=label4.caption=""
then it is changing but only showing False statement. I want a value i.e 0.00. How can I do this..

updated code.......

Expand|Select|Wrap|Line Numbers
  1.   On Error Resume Next
  2.   data1.ActiveConnection = con
  3.   data1.CommandText = "select sum(amunt) from amn where mon & yr &      schm='" & (Combo1.Text) & "' & '" & (Text1.Text) & "''"
  4.   rs.Open data1, , adOpenDynamic, adLockReadOnly
  5.   If Not rs.EOF Then
  6.     subs = rs.Fields(0)  /data field
  7.     Label9.Caption = subs
  8.   End If
  9.   subs=label4.caption=""    /I have added this
  10.   rs.Close
Please let me know.
Nov 19 '07 #5
Killer42
8,435 Expert 8TB
Um... Ok, got it!

It looks as though a little VB syntax lesson is in order.

Can you tell me what you think this line does?
Expand|Select|Wrap|Line Numbers
  1. subs = label4.caption = ""
Also, I have another question. Does "/" indicate a comment? If you are going to post code, please stick to actual valid code, so people can test it.
Nov 19 '07 #6

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

Similar topics

3
by: BlackFireNova | last post by:
This concerns an Access 2002 (XP) database. There are two fields, "Notes" (Memo Field) and "Notes Update" on a form (among others) which I am concerned with here. Problem: I need to be able...
5
by: ND | last post by:
I need to create a separate field from 4 fields, "street address", "city", "State" and "zip code". For example, Street address - 100 Forest Street City - Seattle State - WA Zip - 05555 ...
26
by: temp | last post by:
Hi, My boss is asking me to generate a column mapping report of all the queries. Basically, we get our data from ORACLE. There's a queary that create new table from ORACLE tables. Then, there...
18
by: Dixie | last post by:
Can I set the Format property in a date/time field in code? Can I set the Input Mask in a date/time field in code? Can I set the Format of a Yes/No field to Checkbox in code? I am working on...
2
by: Brett | last post by:
My database has 2 tables: Table1 & Table2. If a field is not null on a record in table2, then the not null fields in table1 that correspond to the records in table1 needs to be updated to match the...
9
by: sellcraig | last post by:
Microsoft access 2 tables table "data main" contains a field called "code" table "ddw1" is created from a make table query of "data main" Goal- the data in "code" field in needs to...
13
by: Lee | last post by:
I have this function that doesn't work. I pass it the td element and an id, and it makes an input field inside the td. That part workds. What doesn't work is that I want to add an "onkeyup" on...
9
by: Ecohouse | last post by:
I have a main form with two subforms. The first subform has the child link to the main form identity key. subform1 - Master Field: SK Child Field: TrainingMasterSK The second subform has a...
1
by: roveagh1 | last post by:
Hi I've been using the 2 year old link below to repeat values from previous record field into current corresponding field. It's worked fine for text but the last piece of advice was to use the same...
3
by: klbachrodt | last post by:
Hi all - I've been browsing this forum for a while now, looking for help, and finally decided to join and ask my question, since I'm not terribly good at writing SQL queries in Access. Here is my...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...
0
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...

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.