Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
XML
Friends the problem for calculating the sum of two fields is resolved. Thanks to you all but there is one more problem in that:
actually i need to display the sum of these two fields(refund and sub) on a VB6 data report using MS Access database. If there is only one record based on the cretaria (select * from employees where Designation='" & cmbodesig.Text & "') then it is displaying the sum but if there are two or more employees with a particular designation it loops through all but displays the total sum on the report which is creating a problem.
I want like
name     designation   ref   sub   total(sum of ref+sub of each employee)

and under these columns i want the individual records
The code which i am trying is
<code>
rs.MoveFirst
Dim cc, xx, tt As Long
  cc = rs.Fields(16)
  xx = rs.Fields(17)
tt = cc + xx
Do While Not rs.EOF

 DataReport2.Sections("Section1").Controls("label16").Caption = tt
 rs.MoveNext
 Loop
</code>
please help



Thank you

Sarfaraz
Posted
Updated 28-Jun-13 16:07pm
v4
Comments
Maciej Los 25-Jun-13 16:31pm    
Is it MS Access report?
sarfarazbhat 25-Jun-13 22:57pm    
Yes sir, MS Access as back end with VB 6.0 as front end
Maciej Los 26-Jun-13 6:02am    
What is DataReport1? CrystalReport, ReportViewer?
What you mean VB: VB6 or VB.NET?
Comparison of Visual Basic and Visual Basic .NET[^]
sarfarazbhat 26-Jun-13 9:00am    
Sir it is visual basic 6.0 inbuilt data report not crystal reports and it is vb6 not vb.net and database is Ms access.
Ron Beyer 27-Jun-13 10:20am    
Can you please post the code that you use to add the two fields?

1 solution

Hello friends
I find the solution by looking into my code
the code that worked is as
<br />
Set rs = New ADODB.Recordset<br />
rs.Open "select * from employees where Designation='" & cmbodesig.Text & "'", Con, adOpenDynamic, adLockPessimistic<br />
Dim cc, xx, tt As Integer<br />
  cc = rs.Fields(16)<br />
  xx = rs.Fields(17)<br />
tt = cc + xx<br />
msgbox tt<br />
<br />

Thank you all esp. Ron Beyer and Maciej Los for their involvement into my question
Thank you
 
Share this answer
 
v3
Comments
sarfarazbhat 28-Jun-13 9:56am    
Friends the problem for calculating the sum of two fields is resolved. Thanks to you all but there is one more problem in that:
actually i need to display the sum of these two fields(refund and sub) on a VB6 data report using MS Access database. If there is only one record based on the cretaria (select * from employees where Designation='" & cmbodesig.Text & "') then it is displaying the sum but if there are two or more employees with a particular designation it loops through all but displays the total sum on the report which is creating a problem.
I want like
name designation ref sub total(sum of ref+sub of each employee)

and under these columns i want the individual records
The code which i am trying is

rs.MoveFirst
Dim cc, xx, tt As Long
cc = rs.Fields(16)
xx = rs.Fields(17)
tt = cc + xx
Do While Not rs.EOF

DataReport2.Sections("Section1").Controls("label16").Caption = tt
rs.MoveNext
Loop

please help

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900