By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,638 Members | 2,204 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,638 IT Pros & Developers. It's quick & easy.

Invalid Use of Null error?

P: 26
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
Sep 19 '07 #1
Share this Question
Share on Google+
3 Replies


FishVal
Expert 2.5K+
P: 2,653
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.
Sep 19 '07 #2

P: 26
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...
Sep 19 '07 #3

FishVal
Expert 2.5K+
P: 2,653
You are welcome.

Best regards,
Fish
Sep 19 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.