-
1 Attachment(s)
Total calculation
hello,please help with the total calculation.basically i use vb6 datareport to display the Total amount.i have problem with the Total display at the datareport.
for example:
8+5=13 but the report display result is 85.
this is my code:
Code:
Dim strSQL As String
Dim conDataConnection As Connection
Dim departmment As String
Dim enddate As String
deptOTsummary.Orientation = rptOrientLandscape
deptOTsummary.Show
department = cbodepartment.Text
Set conDataConnection = New Connection
conDataConnection.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " & App.Path & _
"\Overtime.mdb;Persist Security Info=False"
Dim rs As New ADODB.Recordset
strSQL = "SELECT * FROM Overtime where Department='" & department & "'"
rs.Open strSQL, conDataConnection, adOpenStatic, adLockOptimistic
While Not rs.EOF
' total = total + rs("Othours").valu
If IsNull(rs("OtHours").Value) Then
total = total + 0
Else
total = total + rs("OtHours").Value
End If
rs.MoveNext
Wend
'set the database source in rs
deptOTsummary.Sections("Section5").Controls.Item("Label15").Caption = Format(total, "#,##0.00")
Set deptOTsummary.DataSource = rs
'then set the field
deptOTsummary.Sections("section1").Controls.Item("Text1").DataField = "EmployeeName"
deptOTsummary.Sections("section1").Controls.Item("Text2").DataField = "EmployeeNo"
deptOTsummary.Sections("section1").Controls.Item("Text3").DataField = "Designation"
deptOTsummary.Sections("section1").Controls.Item("Text4").DataField = "Department"
deptOTsummary.Sections("section1").Controls.Item("Text5").DataField = "Shift"
deptOTsummary.Sections("section1").Controls.Item("Text6").DataField = "OvertimeDate"
deptOTsummary.Sections("section1").Controls.Item("Text7").DataField = "TimeFrom"
deptOTsummary.Sections("section1").Controls.Item("Text8").DataField = "TimeTo"
deptOTsummary.Sections("section1").Controls.Item("Text9").DataField = "Breaktime"
deptOTsummary.Sections("section1").Controls.Item("Text10").DataField = "OtRate"
deptOTsummary.Sections("section1").Controls.Item("Text11").DataField = "CategoryDay"
deptOTsummary.Sections("section1").Controls.Item("Text12").DataField = "WorkDescript"
deptOTsummary.Sections("section1").Controls.Item("Text13").DataField = "Othours"
i post the error display image here.
thanks for help!
-
Re: Total calculation
Try
Code:
total = total + Val(rs("OtHours").Value)
-
Re: Total calculation
How is the variable "total" dimensioned?