Error Invalid use of null?

  • Thread starter Thread starter Jean
  • Start date Start date
J

Jean

Hi,

First I did not create this. The following code is a
funtion that the form calls. It seems like it is working
and at the very end it gives me this error in
Ivo_Sum_ADJ94 Invalid use of null. I can see the error
handler say MsgBox "Error in " & "ivo_sum_adj" what does
the 94 represent.. When I debug and run the output it
looks like everything has populated into the tables so I
am not sure what this error is and what to look for to fix
it.

Thanks for any help!


Public Sub ivo_sum_adj(m, y)
On Error Resume Next
Dim xsql
Dim xrs As Recordset
Dim ter
Dim cat
Dim mamt As Double
Dim yamt As Double


sql = "select TERR1,CATEGORY from tbl_ivo_ytd group by
TERR1,CATEGORY order by TERR1"
Set rs = CurrentDb.OpenRecordset(sql)

Do Until rs.EOF

ter = rs!TERR1
cat = rs!category

xsql = "select AMT from
tbl_ivo_summary where category='" & cat & "' and TERR1='"
& ter & "'"
Set xrs = CurrentDb.OpenRecordset
(xsql)
Debug.Print xsql

If xrs.EOF = True And xrs.BOF =
True Then
mamt = 0
Else

mamt = xrs!amt

End If

xrs.Close
Set xrs = Nothing

xsql = "select sum(AMT)as am from
tbl_ivo_ytd where category='" & cat & "' and TERR1='" &
ter & "' and TRADE_MONTH<=" & m & " and TRADE_YEAR=" & y
& ""
Set xrs = CurrentDb.OpenRecordset
(xsql)

If xrs.EOF = True And xrs.BOF =
True Then

Else

yamt = xrs!am

End If

xrs.Close
Set xrs = Nothing


xsql = "select * from
tbl_rpt_sale_goal where TERR1='" & ter & "' and
category='" & cat & "'"
Set xrs = CurrentDb.OpenRecordset
(xsql)
If Not xrs.EOF Then
xrs.Edit
xrs!sales = xrs!sales - mamt
xrs!ytd_sales = xrs!ytd_sales -
yamt
xrs.Update
End If
xrs.Close
Set xrs = Nothing


rs.MoveNext
Loop

rs.Close
Set rs = Nothing


If Err.Number <> 0 Then
MsgBox "Error in " & "ivo_sum_adj" & Err.Number &
Err.Description
End If
End Sub
 
Jean said:
Hi,

First I did not create this. The following code is a
funtion that the form calls. It seems like it is working
and at the very end it gives me this error in
Ivo_Sum_ADJ94 Invalid use of null. I can see the error
handler say MsgBox "Error in " & "ivo_sum_adj" what does
the 94 represent.. When I debug and run the output it
looks like everything has populated into the tables so I
am not sure what this error is and what to look for to fix
it.

The procedure does 'sloppy error handling': the statement On Error
Resume Next basically means "see errors, but ignore them (for now)". The
tail of the procedure informs you of the last error that occurred: 94
Invalid Use of Null.
You can try removing the statement On Error Resume Next; most likely the
procedure will now fail somewhere (with the same starting conditions,
that is). Where does it fail?
 
First I did not create this. The following code is a
funtion that the form calls. It seems like it is working
and at the very end it gives me this error in
Ivo_Sum_ADJ94 Invalid use of null. I can see the error
handler say MsgBox "Error in " & "ivo_sum_adj" what does
the 94 represent.. When I debug and run the output it
looks like everything has populated into the tables so I
am not sure what this error is and what to look for to fix
it.

The 94 is the error number of the "Illegal Use of Null" error. To find
out what line's causing it, set a Breakpoint on an early line of the
code - open the code in the VBA editor and click in the bar to the
left of the code. Run the form, and when the code reaches the
breakpoint it will stop. You can then step through the code line by
line by pressing F8; you can check the values of variables by typing

?Variablename

in the Immediate window, or you can set a "watch" on a variable to
display its value as it changes. In any case you'll be able to
determine just where in the code you're getting the error.
 
Comment out the On Error Resume Next so Access can halt the
code on the line that actually has the error.

The 94 is the error number of the error.
 
Back
Top