I am trying to run the following function. I am testing two variables (whcih I have declared as public in the general declaration section): SFsum and rcount.
I want to warn the user If SFsum <> rcount. It works fine when I have SFsum and rcount both equal to 1, 2 or 4. But When both of them are equal to 3, it still thinks they are not equal and warn the user. Below is my code.
It's driving me nuts because it works fine for 1, 2 or 4but doesn't work at all when the value is 4.
Any ideas/thoughts will be highly appreciated. Thanks!
' *****************************************************
Public Function SFSummation()
Dim k As Integer
Dim ObjMyDB As Database
Dim r As Recordset
Dim r1 As Recordset
Set ObjMyDB = DBEngine.Workspaces(0).Databases(0)
Set r = ObjMyDB.OpenRecordset("Graph_tbl", DB_OPEN_DYNASET)
Set r1 = ObjMyDB.OpenRecordset("OutPut_tbl", DB_OPEN_DYNASET)
SFsum = 0
rcount = 0
r.MoveFirst
Do While Not r.EOF
SFsum = SFsum + r![Factor]
r.MoveNext
Loop
r1.MoveFirst
For k = 1 To 4
rcount = rcount + Abs(r1.Fields(1 + k) > 0)
Next k
r.Close
r1.Close
ObjMyDB.Close
Set r = Nothing
Set r1 = Nothing
Set ObjMyDB = Nothing
Debug.Print SFsum
Debug.Print rcount
If SFsum <> rcount Then
Debug.Print "Test Not Equal"
End If
End Function
***********************************************************
I want to warn the user If SFsum <> rcount. It works fine when I have SFsum and rcount both equal to 1, 2 or 4. But When both of them are equal to 3, it still thinks they are not equal and warn the user. Below is my code.
It's driving me nuts because it works fine for 1, 2 or 4but doesn't work at all when the value is 4.
Any ideas/thoughts will be highly appreciated. Thanks!
' *****************************************************
Public Function SFSummation()
Dim k As Integer
Dim ObjMyDB As Database
Dim r As Recordset
Dim r1 As Recordset
Set ObjMyDB = DBEngine.Workspaces(0).Databases(0)
Set r = ObjMyDB.OpenRecordset("Graph_tbl", DB_OPEN_DYNASET)
Set r1 = ObjMyDB.OpenRecordset("OutPut_tbl", DB_OPEN_DYNASET)
SFsum = 0
rcount = 0
r.MoveFirst
Do While Not r.EOF
SFsum = SFsum + r![Factor]
r.MoveNext
Loop
r1.MoveFirst
For k = 1 To 4
rcount = rcount + Abs(r1.Fields(1 + k) > 0)
Next k
r.Close
r1.Close
ObjMyDB.Close
Set r = Nothing
Set r1 = Nothing
Set ObjMyDB = Nothing
Debug.Print SFsum
Debug.Print rcount
If SFsum <> rcount Then
Debug.Print "Test Not Equal"
End If
End Function
***********************************************************