Connecting Tech Pros Worldwide Forums | Help | Site Map

Invalid Use of Null error?

Newbie
 
Join Date: Sep 2007
Location: Adelaide,Australia
Posts: 26
#1: Sep 19 '07
Hi,

I am using Ms Access 2000.

i wrote a simple VBA Code to perform addition operation based on the user input.

I used AfterUpdate event for each fields to update the value to Sub_Total

but when i run the code, the value is not updated in Sub_Total field. instead, the field is totally blank and i inserted MsgBox Sub_Total to check whether addtion works fine, i got an error message "Invalid Use of Null".

the code is large so i just paste a part of it.

Code:

Private Sub FaM_Rate_AfterUpdate()

updateFaM_Cost

End Sub
----------------------------------------------------------------------------------
Private Sub updateFaM_Cost()

FaM_Cost.Value = FaM_Rate.Value * FaM_Sheets.Value
updateSubTotal

End Sub
------------------------------------------------------------------------------------
Private Sub FaM_Sheets_AfterUpdate()

updateFaM_Cost

End Sub
---------------------------------------------------------------------------------------
Private Sub FM_Metres_AfterUpdate()

updateFMCost

End Sub
--------------------------------------------------------------------------------------
Private Sub FM_Rate_AfterUpdate()

updateFMCost

End Sub
-------------------------------------------------------------------------------------
Private Sub updateFMCost()

FM_Cost.Value = FM_Metres.Value * FM_Rate.Value

updateSubTotal

End Sub
-------------------------------------------------------------------------------------
Private Sub updateSubTotal()

Sub_Total.Value = (FM_Cost.Value) + (FaM_Cost.Value)
MsgBox Sub_Total

End Sub



I am getting the value for FM_Cost and FaM_Cost. i am getting an error message in updateSubTotal() as "invalid use of null"

could anyone help me in this regard

thanks

FishVal's Avatar
Expert
 
Join Date: Jun 2007
Location: Israel
Posts: 2,584
#2: Sep 19 '07

re: Invalid Use of Null error?


Hi, Asle.

Empty controls contain Null's.
Every expression either logic or arithmetic with Null operand will return Null.
e.g.
5+Null=Null

If you are expecting empty controls values to be treated as zeroes, then you should use Nz() function.
e.g.
when
FM_Cost.Value = 5
FaM_Cost.Value = Null
Sub_Total.Value = (FM_Cost.Value) + (FaM_Cost.Value) = 5 + Null = Null
Sub_Total.Value = Nz(FM_Cost.Value) + Nz(FaM_Cost.Value) = 5 + 0 = 5

Hope this makes sense.
Newbie
 
Join Date: Sep 2007
Location: Adelaide,Australia
Posts: 26
#3: Sep 19 '07

re: Invalid Use of Null error?


Quote:

Originally Posted by FishVal

Hi, Asle.

Empty controls contain Null's.
Every expression either logic or arithmetic with Null operand will return Null.
e.g.
5+Null=Null

If you are expecting empty controls values to be treated as zeroes, then you should use Nz() function.
e.g.
when
FM_Cost.Value = 5
FaM_Cost.Value = Null
Sub_Total.Value = (FM_Cost.Value) + (FaM_Cost.Value) = 5 + Null = Null
Sub_Total.Value = Nz(FM_Cost.Value) + Nz(FaM_Cost.Value) = 5 + 0 = 5

Hope this makes sense.

thanks FishVal

that solves my problem...

thanks a lot for ur help.

chuz...
FishVal's Avatar
Expert
 
Join Date: Jun 2007
Location: Israel
Posts: 2,584
#4: Sep 19 '07

re: Invalid Use of Null error?


You are welcome.

Best regards,
Fish
Reply