Overflow and Null Value - plz help

Janjang

Registered User.
Local time
Today, 10:15
Joined
Oct 17, 2005
Messages
80
hi there..

i make simple system to make calculation in the end of each month bout point that car salesman from customer bout our their service

i make cmd button to calculate where criteria (by salesman name and month) based on combo box then the result (calculation) return to box..

i make 2 form:-
1. to edit record
2. to calculate

i've no problem in form 1 but in form 2 it say my calculation overflow and when debug. i c my calculation value = null

i let u c my coding and i attack my db to u guy.. plz help me.. i need help ASAP

Private Sub cmd_calculate_Click()

Dim rsSurvey As DAO.Recordset
Dim strSurvey As String
Dim Counter, Aaa1, Aaa2, Aaa3, Aaa4, Aaa5, Aaa6, Aaa7, Bbb1, Bbb2, Bbb3, Bbb4, Bbb5, Bbb6, Bbb7, Bbb8, Bbb9, Ccc1, Ccc2, Ccc3, Ccc4, Ccc5, Ccc6, Ccc7, Ccc8, Ccc9, Ddd1 As Integer


Set rsSurvey = CurrentDb.OpenRecordset("q_Survey")

''' strSurvey = Forms!f_Survey.RecordsetClone.RecordCount
strSurvey = rsSurvey.RecordCount
Me!TextTest = strSurvey ' try to see record(i mean row) count
' but it only show 1 instead of 4
' i think i make wrong code

Do While Not rsSurvey.EOF
If rsSurvey.Fields("SalesmanName") = Me.SalesmanName2 Then
If rsSurvey.Fields("MonthRegister") = Me.Month Then
If rsSurvey.Fields("YearRegister") = Me.Year Then

Aaa1 = rsSurvey.Fields("A1").Value + Aaa1
Aaa2 = rsSurvey.Fields("A2").Value + Aaa2
Aaa3 = rsSurvey.Fields("A3").Value + Aaa3
Aaa4 = rsSurvey.Fields("A4").Value + Aaa4
Aaa5 = rsSurvey.Fields("A5").Value + Aaa5
Aaa6 = rsSurvey.Fields("A6").Value + Aaa6
Aaa7 = rsSurvey.Fields("A7").Value + Aaa7
Bbb1 = rsSurvey.Fields("B1").Value + Bbb1
Bbb2 = rsSurvey.Fields("B2").Value + Bbb2
Bbb3 = rsSurvey.Fields("B3").Value + Bbb3
Bbb4 = rsSurvey.Fields("B4").Value + Bbb4
Bbb5 = rsSurvey.Fields("B5").Value + Bbb5
Bbb6 = rsSurvey.Fields("B6").Value + Bbb6
Bbb7 = rsSurvey.Fields("B7").Value + Bbb7
Bbb8 = rsSurvey.Fields("B8").Value + Bbb8
Bbb9 = rsSurvey.Fields("B9").Value + Bbb9
Ccc1 = rsSurvey.Fields("C1").Value + Ccc1
Ccc2 = rsSurvey.Fields("C2").Value + Ccc2
Ccc3 = rsSurvey.Fields("C3").Value + Ccc3
Ccc4 = rsSurvey.Fields("C4").Value + Ccc4
Ccc5 = rsSurvey.Fields("C5").Value + Ccc5
Ccc6 = rsSurvey.Fields("C6").Value + Ccc6
Ccc7 = rsSurvey.Fields("C7").Value + Ccc7
Ccc8 = rsSurvey.Fields("C8").Value + Ccc8
Ccc9 = rsSurvey.Fields("C9").Value + Ccc9
Ddd1 = rsSurvey.Fields("D1").Value + Ddd1
Counter = Counter + 1
rsSurvey.MoveNext
Else
rsSurvey.MoveNext
End If
Else
rsSurvey.MoveNext
End If
Else
rsSurvey.MoveNext
End If
Loop

Me.AA1 = Aaa1 / Counter
Me.AA2 = Aaa2 / Counter
Me.AA3 = Aaa3 / Counter
Me.AA4 = Aaa4 / Counter
Me.AA5 = Aaa5 / Counter
Me.AA6 = Aaa6 / Counter
Me.AA7 = Aaa7 / Counter
Me.BB1 = Bbb1 / Counter
Me.BB2 = Bbb2 / Counter
Me.BB3 = Bbb3 / Counter
Me.BB4 = Bbb4 / Counter
Me.BB5 = Bbb5 / Counter
Me.BB6 = Bbb6 / Counter
Me.BB7 = Bbb7 / Counter
Me.BB8 = Bbb8 / Counter
Me.BB9 = Bbb9 / Counter
Me.CC1 = Ccc1 / Counter
Me.CC2 = Ccc2 / Counter
Me.CC3 = Ccc3 / Counter
Me.CC4 = Ccc4 / Counter
Me.CC5 = Ccc5 / Counter
Me.CC6 = Ccc6 / Counter
Me.CC7 = Ccc7 / Counter
Me.CC8 = Ccc8 / Counter
Me.CC9 = Ccc9 / Counter
Me.DD1 = Ddd1 / Counter

End Sub

note that i'm new with Access coding..

thanks...
 

Attachments

Me.AA1 = Aaa1 / Counter
Me.AA2 = Aaa2 / Counter
Me.AA3 = Aaa3 / Counter
Me.AA4 = Aaa4 / Counter
Me.AA5 = Aaa5 / Counter


Try using the Nz Function around your code like so
Nz(Me.AA1, 0) = Aaa1 / Counter

I tried it on your dband it didnt fail until it reached the code without the NZ

Hope this helps
 
To start off:
Dim Counter, Aaa1, Aaa2, Aaa3, Aaa4, Aaa5, Aaa6, Aaa7, Bbb1, Bbb2, Bbb3, Bbb4, Bbb5, Bbb6, Bbb7, Bbb8, Bbb9, Ccc1, Ccc2, Ccc3, Ccc4, Ccc5, Ccc6, Ccc7, Ccc8, Ccc9, Ddd1 As Integer

This doesnt work the way you think.... All variables now are variant except Ddd1, which is an integer... Creative naming by the way ;)
Instead you sould dim on a seperate line or add as integer before each comma.
have you ever though about using an array??

One and a half:
If you were using an array instad of type in all that 1,2,3, etc number you could do something with a loop instead... Reducing the number of lines needed drasticaly

Second:
try using Me. instead of Me!

Third:
Assuming Forms!f_Survey is your form and also using the save data as the query...
Me.recordsetclone.movelast
me.recordsetclone.recordcout
If not...
Add a rsSurvey.Movelast before the recordcount and a rsSurvey.movefirst after to fetch the right number of records and return to the start of the query. YES it is a pain...

Four:
If rsSurvey.Fields("SalesmanName") = Me.SalesmanName2 Then
If rsSurvey.Fields("MonthRegister") = Me.Month Then
If rsSurvey.Fields("YearRegister") = Me.Year Then
why not 'simply' use AND?
If rsSurvey.Fields("SalesmanName") = Me.SalesmanName2 and If rsSurvey.Fields("MonthRegister") = Me.Month and rsSurvey.Fields("YearRegister") = Me.Year Then

Five:
rsSurvey.MoveNext
Else
rsSurvey.MoveNext
End If
Else
rsSurvey.MoveNext
End If
Else
rsSurvey.MoveNext
End If
Loop
Note that on each Else you are doing a movenext... Why have the else and those seperate movenext???
End If
End If
End If
rsSurvey.MoveNext
Loop
Also I hop you indent your own code.... If not you should... And when posting that indended code on the forum use [ code ] and [/ code ] (without the spaces) to mark the start and stop of the code...
Code:
            End If
        End If
    End If
    rsSurvey.MoveNext
Loop
Indeted its much easier to read....

Six:
Why do the If to search for the sales man at all and not using the query to limit the search right there?
so instead of Set rsSurvey = CurrentDb.OpenRecordset("q_Survey")
try using something like
Set rsSurvey = CurrentDb.OpenRecordset("Select * from q_Survey where SalesmanName = '" & Me.SalesmanName2 & "'")
Expand this to include the others...

Six and a half:
in general you should not search on names ever... Sooner or later it will cause problems where people end up with the same name....

Seven, your 'real' question:
When deviding by Null or Zero you have a problem... cause you simply cannot
Since counter is a variant and not an integer... this no good either (see 1)

AND you should allways initialize your variables...
ccc1 = 0
counter = 0 etc...

sorry if it all is to much.... and to harsch.... just trying to help
 
Smart said:
Me.AA1 = Aaa1 / Counter
Me.AA2 = Aaa2 / Counter
Me.AA3 = Aaa3 / Counter
Me.AA4 = Aaa4 / Counter
Me.AA5 = Aaa5 / Counter


Try using the Nz Function around your code like so
Nz(Me.AA1, 0) = Aaa1 / Counter

I tried it on your dband it didnt fail until it reached the code without the NZ

Hope this helps
I dont think this will help Smart.... If it does... its strange...
I would think this would work...
Me.AA1 = nz(Aaa1 / Counter)

Oh and I didnt open the DB, just gave comments bassed upon the code....
 
wow.. thanks for helping...

yeah,i meed to learn more bout efficient and effetive coding...
i try now..ill give th result later..
 
namliam said:
To start off:

Six and a half:
in general you should not search on names ever... Sooner or later it will cause problems where people end up with the same name....


yup, i need to search data wit same name, to add, then devide it in then end of month, that y i use to serach name and month
 
i got new coding.. seems ok but stuck wit parameter error.. any1 can help?

Code:
Private Sub cmd_calculate_Click()

   Dim daoRS As DAO.Recordset
   Dim strRS As String
   strRS = _
      "SELECT COUNT(*) AS [Counter], " & _
      " AVG(NZ([A1],0)) AS [Aaa1], AVG(NZ([A2],0)) AS [Aaa2], " & _
      " AVG(NZ([A3],0)) AS [Aaa3], AVG(NZ([A4],0)) AS [Aaa4], " & _
      " AVG(NZ([A5],0)) AS [Aaa5], AVG(NZ([A6],0)) AS [Aaa6], " & _
      " AVG(NZ([A7],0)) AS [Aaa7], " & _
      " AVG(NZ([B1],0)) AS [Bbb1], AVG(NZ([B2],0)) AS [Bbb2], " & _
      " AVG(NZ([B3],0)) AS [Bbb3], AVG(NZ([B4],0)) AS [Bbb4], " & _
      " AVG(NZ([B5],0)) AS [Bbb5], AVG(NZ([B6],0)) AS [Bbb6], " & _
      " AVG(NZ([B7],0)) AS [Bbb7], AVG(NZ([B8],0)) AS [Bbb8], " & _
      " AVG(NZ([B9],0)) AS [Bbb9], " & _
      " AVG(NZ([C1],0)) AS [Ccc1], AVG(NZ([C2],0)) AS [Ccc2], " & _
      " AVG(NZ([C3],0)) AS [Ccc3], AVG(NZ([C4],0)) AS [Ccc4], " & _
      " AVG(NZ([C5],0)) AS [Ccc5], AVG(NZ([C6],0)) AS [Ccc6], " & _
      " AVG(NZ([C7],0)) AS [Ccc7], AVG(NZ([C8],0)) AS [Ccc8], " & _
      " AVG(NZ([C9],0)) AS [Ccc9], " & _
      " AVG(NZ([D1],0)) AS [Ddd1] " & _
      " FROM [q_Survey] " & _
      " WHERE [SalesmanName] ='" & Me.SalesmanName2 & "' " & _
      " AND [MonthRegister]= " & Me.Month & " " & _
      " AND [YearRegister] = " & Me.Year & " "
'
   Set daoRS = CurrentDb.OpenRecordset(strRS)
'
   With daoRS
      If .EOF Then
         MsgBox "No Record Found"
         Me.AA1 = ""
         Me.AA2 = ""
         Me.AA3 = ""
         Me.AA4 = ""
         Me.AA5 = ""
         Me.AA6 = ""
         Me.AA7 = ""
         Me.BB1 = ""
         Me.BB2 = ""
         Me.BB3 = ""
         Me.BB4 = ""
         Me.BB5 = ""
         Me.BB6 = ""
         Me.BB7 = ""
         Me.BB8 = ""
         Me.BB9 = ""
         Me.CC1 = ""
         Me.CC2 = ""
         Me.CC3 = ""
         Me.CC4 = ""
         Me.CC5 = ""
         Me.CC6 = ""
         Me.CC7 = ""
         Me.CC8 = ""
         Me.CC9 = ""
         Me.DD1 = ""
      Else
         Me.TextTest = !Counter
         Me.AA1 = !Aaa1
         Me.AA2 = !Aaa2
         Me.AA3 = !Aaa3
         Me.AA4 = !Aaa4
         Me.AA5 = !Aaa5
         Me.AA6 = !Aaa6
         Me.AA7 = !Aaa7
         Me.BB1 = !Bbb1
         Me.BB2 = !Bbb2
         Me.BB3 = !Bbb3
         Me.BB4 = !Bbb4
         Me.BB5 = !Bbb5
         Me.BB6 = !Bbb6
         Me.BB7 = !Bbb7
         Me.BB8 = !Bbb8
         Me.BB9 = !Bbb9
         Me.CC1 = !Ccc1
         Me.CC2 = !Ccc2
         Me.CC3 = !Ccc3
         Me.CC4 = !Ccc4
         Me.CC5 = !Ccc5
         Me.CC6 = !Ccc6
         Me.CC7 = !Ccc7
         Me.CC8 = !Ccc8
         Me.CC9 = !Ccc9
         Me.DD1 = !Ddd1
      End If
   End With
'
End Sub

it stuck here..
Code:
Set daoRS = CurrentDb.OpenRecordset(strRS)
can u help me?


thanks
 
" WHERE [SalesmanName] ='" & Me.SalesmanName2 & "' "
should probably be
" WHERE [SalesmanName] =""" & Me.SalesmanName2 & """ "

If that fails, add a "Debug.print daoRS" to you coding. Then copy paste the query to a normal query and find out what parameter the query requires.
 

Users who are viewing this thread

Back
Top Bottom