run time error 94 , invalid use of null

i'm getting run time error 94 , invalid use of null
how to solve this? thx

  • 6 unbound textboxes , all set to Null onload.
  • if only 1 textbox retreive value input by user , txtTotal show that value and ignore other null textboxes.(User may input to txt2 or others as first value and leave txt1 as null)
  • if 2 textboxes retreive values, txtTotal shows sum of those 2 values and ignore other null textboxes.
  • if more textboxes retreive value,condition same as above
  • txtTotal is updated when any of the textboxes retreive value.

Codes :
Private Sub txt1_AfterUpdate()
Me.txtTotal = Val(txt1.Value) + Val(txt2.Value) + Val(txt3.Value) + Val(txt4.Value) + Val(txt5.Value)
End Sub

same code goes to Private Sub txt2_AfterUpdate() and so on.
Poop HolyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

NorieAnalyst Assistant Commented:
Try adding this function in a standard module.
Function SumAll(ParamArray vals()) As Single
Dim I As Long

    For I = LBound(vals) To UBound(vals)
        SumAll = SumAll + Val(Nz(vals(I), 0))
    Next I
End Function

Open in new window

You can then use it in the AfterUpdate event of the textboxes like this.
Private Sub Text1_AfterUpdate()
    Me.txtTotal = SumAll(txt1.Value, txt2.Value, txt3.Value, txt4.Value, txt5.Value)
End Sub

Open in new window


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
John TsioumprisSoftware & Systems EngineerCommented:
Me.txtTotal = Val(Nz(txt1.Value,"") + Val(Nz(txt2.Value,"") + Val(Nz(txt3.Value,"") + Val(Nz(txt4.Value,"") + Val(Nz(txt5.Value,"")

Open in new window

Poop HolyAuthor Commented:
Solved my problem perfectly, thx bro
Private Sub txt1_AfterUpdate()
    Me.txtTotal = Val(""&txt1.Value) + Val(""&txt2.Value) + Val(""&txt3.Value) + Val(""&txt4.Value) + Val(""&txt5.Value)
End Sub

Open in new window

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.