473,378 Members | 1,620 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,378 software developers and data experts.

Getting Sum of Amount paid from a ms Access table using modules in vb6.0

Am trying to use this code to get the sum of amount paid but its giving me the output as True instead of the sum. where is the problem?

Expand|Select|Wrap|Line Numbers
  1. Dim DataEnvironment1 As New ADODB.Command
  2. Dim rs As New ADODB.Recordset
  3. Dim subs As String
  4.  
  5. On Error Resume Next
  6.     DataEnvironment1.ActiveConnection = con
  7.     DataEnvironment1.CommandText = "select sum(Paid) from Payment"
  8.     rs.Open DataEnvironment1, , adOpenDynamic, adLockReadOnly
  9.     If Not rs.EOF Then
  10.     subs = rs.Fields(8)
  11.     lblTotal.Caption = subs
  12.     End If
  13.     subs = txtPaid.Text = ""
  14.     rs.Close
Jun 14 '13 #1

✓ answered by Rabbit

Line 10 is your problem. You have no Fields(8). Your query only returns one field, how can it possibly have a Fields(8)? I'm surprised it didn't give you an out of bounds error.

4 1911
Rabbit
12,516 Expert Mod 8TB
Line 10 is your problem. You have no Fields(8). Your query only returns one field, how can it possibly have a Fields(8)? I'm surprised it didn't give you an out of bounds error.
Jun 14 '13 #2
yes that's where the problem is but field Paid is number 8 in my database so don't know what to do now. i have a Ms Access table titled Payment with fields PaymentID, StudentID, Name, Surname, AdminNO, Class, Term, Fee, Paid, Bal, ModeOfPayment, Number, PaidOf, Date. i want to get the total from field paid to display on my Vb6.0 Form named frmPayment on lblTotal by press of a command button namely cmdTotal. Which code will i put on this command button and am using module to connect to the database? Please help!
Jun 15 '13 #3
Rabbit
12,516 Expert Mod 8TB
It doesn't matter that the field in your table is the 8th field. It only sees the fields returned in the recordset. In this case, you only have 1 field in your recordset, so you need to use Fields(0).
Jun 15 '13 #4
thanks so much its working
Jun 17 '13 #5

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

Similar topics

5
by: thejackofall | last post by:
Hi. This is killing me. I am trying to insert a row into an Access table, but it's giving me an exception as below. "Syntax error in INSERT INTO statement." When I debug and look at the...
2
by: SenseForAll | last post by:
First please note I am a novice at VBA and not even that experienced with DAO/ADO and MS-SQL. Any assistance is appreciated. That said... I have an application written in Access w/ VBA. I need to...
1
by: JH | last post by:
I have a comma delimited file and I want to export it to an MS access table already designed with appropriate field names. How do I do this programmatically using VB.NET or C#? Thanks for any...
2
by: kkant | last post by:
Hi , I am KKant from Bangalore, India. I have a jos to do, I have to store VB codes in a a Database (Access) table and in Run time I have to read those codes and Exute them. But I dont know how to...
5
by: Hari2005 | last post by:
I try to get width of a table using javascript. Table width is not defined in table. It grows as per the data. Please suggest how to get table width using javascript at run time??????? Thanks in...
1
by: sohiharnek | last post by:
Hi I am new to you people. I want to store a picture in a ms access table using vb 6.0 , pls help
1
by: fishmore | last post by:
MS Access question: I have made an access form with unbound control source fields and have written a Macro that will make a new record and store the data from each unbound field in a table. This...
5
by: MarkTingson | last post by:
Hello guys, im having trouble with this line of code. I'm trying to create a table in access using this piece of code but it says 'Object is no longer valid.' and it points to ocat.Tables.Append...
5
by: abhi3211 | last post by:
i am using java inside java script page. in that page i want to use two dropdown list. in first dropdown list i am getting data from ms-access database. in second dropdown list i want to get data...
0
by: ahmed222too | last post by:
i have a text file contains data (tab delimited), i want to import these data into access table. i want to do this task using visual basic code not by access wizard
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.