Hello,
I'm pulling all my hair out on this one... and help will be greatly appreciated!
I have an access 97 database and i want to look through a table of values and sum up those values that meet my criteria.
the table, NTable2, has the following values:
Nnumb NVal Incrementor
13 1 1
14 2 1
15 3 2
16 4 2
The code I am using is pasted below:
I am expecting a result of 6, 1+2+3 from NVal, hoever the best I can get is the code adding 1 and 2, then multiplying the sum by 3 (giving a result of 9).
It seems to count the values where 'Incrementor' is 1, and then multiplies that by the number of loops till alpha=beta + 1 (i.e. 3).
Is my looping wrong, or is it where I place my code or is Dlookup the wrong function? Maybe I need to use an array?
P.S. the isnull and if statement is there to handle null values which were otherwise causing the code to fail.
I have been stuck on this for 3 days now and cant see what I'm missing.
Sorry if i'm not too clear, its difficult to explain. Thank you.
danial
I'm pulling all my hair out on this one... and help will be greatly appreciated!
I have an access 97 database and i want to look through a table of values and sum up those values that meet my criteria.
the table, NTable2, has the following values:
Nnumb NVal Incrementor
13 1 1
14 2 1
15 3 2
16 4 2
The code I am using is pasted below:
Code:
Private Sub Command27_Click()
Dim Alpha, Beta, Gamma, Delta As Integer
Dim SubTotal, TheTotal, GrandTotal As Integer
Alpha = 1
Beta = 3
Gamma = 13
Delta = 15
TheTotal = 0
GrandTotal = 0
Do Until Alpha = Beta + 1
While Gamma < Delta + 1
If IsNull(SubTotal = DLookup("[Nval]", "Ntable2", "[nnumb] = " & [Gamma] & "and" & "[incrementor]=" & [Alpha])) = True Then
SubTotal = 0
Else: SubTotal = DLookup("[Nval]", "Ntable2", "[nnumb] = " & [Gamma] & "and" & "[incrementor]=" & [Alpha])
End If
TheTotal = TheTotal + SubTotal
Gamma = Gamma + 1
Wend
GrandTotal = GrandTotal + TheTotal
Alpha = Alpha + 1
Loop
MsgBox (GrandTotal)
End Sub
I am expecting a result of 6, 1+2+3 from NVal, hoever the best I can get is the code adding 1 and 2, then multiplying the sum by 3 (giving a result of 9).
It seems to count the values where 'Incrementor' is 1, and then multiplies that by the number of loops till alpha=beta + 1 (i.e. 3).
Is my looping wrong, or is it where I place my code or is Dlookup the wrong function? Maybe I need to use an array?
P.S. the isnull and if statement is there to handle null values which were otherwise causing the code to fail.
I have been stuck on this for 3 days now and cant see what I'm missing.
Sorry if i'm not too clear, its difficult to explain. Thank you.
danial