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

sum() function is not returning value

Expand|Select|Wrap|Line Numbers
  1.  
  2. why this sum function won't work ? 
  3. eg Sum(personal)
  4. lblPersonal.Caption it wont retrieve the sum value of the personal field
  5.  
  6. Dim cn6 As New ADODB.Connection
  7. Dim strCNString4 As String
  8. Dim rs6 As New ADODB.Recordset
  9. Dim intFound6 As Double
  10.  
  11. strCNString6 = "Data Source=" & App.Path & "\PayrollBakeryDB.mdb"
  12. cn6.Provider = "Microsoft Jet 4.0 OLE DB Provider"
  13. cn6.ConnectionString = strCNString6
  14.  
  15. cn6.Open
  16.  
  17.     With rs6
  18.         '.Open "SELECT Sum(personal), Sum(sick), Sum(vacation), Sum(maternity), emp_id, from_date, to_date FROM leavela WHERE Month(from_date)=" & intMonth & " and Year(from_date)=" & intYear & " and Month(to_date)=" & intMonth & " and Year(to_date)=" & intYear & " GROUP BY emp_id, from_date, to_date ", cn6, adOpenDynamic, adLockOptimistic
  19.  
  20.          Do Until .EOF
  21.  
  22.              If !emp_id = txtEmp_ID.Text Then
  23.                    lblPersonal.Caption = rs6.Fields(0) 'here
  24.                    lblSick.Caption = rs6.Fields(1) 'here
  25.                    Vacation.Caption = rs6.Fields(2) 'here
  26.                    lblMaternity.Caption = rs6.Fields(3) 'here
  27.  
  28.                     intFound6 = 1
  29.              End If
  30.  
  31.             .MoveNext
  32.           Loop
  33.  
  34.           'If intFound6 = 0 Then
  35.                    'MsgBox "Employee ID not found !", vbExclamation, "Error"
  36.           'End If
  37.  
  38.      End With
  39.  
  40.  
May 26 '07 #1
2 2115
ADezii
8,834 Expert 8TB
Expand|Select|Wrap|Line Numbers
  1.  
  2. why this sum function won't work ? 
  3. eg Sum(personal)
  4. lblPersonal.Caption it wont retrieve the sum value of the personal field
  5.  
  6. Dim cn6 As New ADODB.Connection
  7. Dim strCNString4 As String
  8. Dim rs6 As New ADODB.Recordset
  9. Dim intFound6 As Double
  10.  
  11. strCNString6 = "Data Source=" & App.Path & "\PayrollBakeryDB.mdb"
  12. cn6.Provider = "Microsoft Jet 4.0 OLE DB Provider"
  13. cn6.ConnectionString = strCNString6
  14.  
  15. cn6.Open
  16.  
  17.     With rs6
  18.         '.Open "SELECT Sum(personal), Sum(sick), Sum(vacation), Sum(maternity), emp_id, from_date, to_date FROM leavela WHERE Month(from_date)=" & intMonth & " and Year(from_date)=" & intYear & " and Month(to_date)=" & intMonth & " and Year(to_date)=" & intYear & " GROUP BY emp_id, from_date, to_date ", cn6, adOpenDynamic, adLockOptimistic
  19.  
  20.          Do Until .EOF
  21.  
  22.              If !emp_id = txtEmp_ID.Text Then
  23.                    lblPersonal.Caption = rs6.Fields(0) 'here
  24.                    lblSick.Caption = rs6.Fields(1) 'here
  25.                    Vacation.Caption = rs6.Fields(2) 'here
  26.                    lblMaternity.Caption = rs6.Fields(3) 'here
  27.  
  28.                     intFound6 = 1
  29.              End If
  30.  
  31.             .MoveNext
  32.           Loop
  33.  
  34.           'If intFound6 = 0 Then
  35.                    'MsgBox "Employee ID not found !", vbExclamation, "Error"
  36.           'End If
  37.  
  38.      End With
  39.  
  40.  
  1. Are the sure the Recordset is returning any Records?
  2. Is the following condition ever being met? (!emp_id = txtEmp_ID.Text )
  3. Change the syntax of the following line of code:
    Expand|Select|Wrap|Line Numbers
    1. !emp_id = txtEmp_ID.Text ==> !emp_id = Me![txtEmp_ID]
    2. NOTE: The Text property is only valid when the Field has the focus.
May 26 '07 #2
nico5038
3,080 Expert 2GB
Best to try the query first in the query editor. (Use a breakpoint and F8 to step through the code and type in the immediate window a "?" followed by the stringing to get the result in textmode for a copy/paste in the query editor.)

Next it's better to use:
Sum(NZ(personal))
as Null values can spoil the result.

Nic;o)
May 26 '07 #3

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 : ...
15
by: ajj | last post by:
Hello All, Yes this is homework, but I have spent a lot of time on it and I am close. I want to be able to count the number of nodes in a tree that have only one child. I can identify the...
30
by: Peter Ammon | last post by:
Howdy, I have four unsigned long longs a, b, c, d. I want to determine whether a+b or c+d is larger, as if there were no overflow. That is, ULLONG_MAX + 5 should be considered larger than 10 +...
2
by: DAHMB | last post by:
I have a column in a report that I want to return a sum of certain criteria from a query between two dates. I set the dates in a form that I launch the report from. My query contains a field...
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...
3
by: azegurb | last post by:
hi I have just took from internet dinamic table. this table is dynamic and its rows dynamically can be increased. but i would like how create SUM function that automatically sums each added row...
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...
5
by: merkam | last post by:
hi, i need a script that: step1: multiple n*1200= m n=0 or 1 or 2 ... step2: sum m+10+20 i have this script i don't now how to assign span with id="five" to value in checkbox plz help me <%@...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
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
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
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...
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
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,...

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.