Adding Money Up

  • Thread starter Thread starter NotGood@All
  • Start date Start date
N

NotGood@All

I have 2 text boxes, 1 for the number of things I'm ordering, the 2nd to show
the total price for the items. It works the first time, but I get an error
on a new record saying "Invalid use of Null" and I dim TabStop1 as currency
but when I assign 30.00 to it I get 30#

Private Sub TheApplication_Exit(Cancel As Integer)
Dim TabStop1 As Currency
Dim TabStop1Cost As Currency
TabStop1 = 30#
TabStop1Cost = Me.ClerkNo * TabStop1
Me.ApplicationMoney = TabStop1Cost
End Sub
 
On Fri, 1 May 2009 13:01:01 -0700, NotGood@All

This is because VBA interprets 30.00 as a double.
(in the Immediate window:)
?vartype(30.00)
5

Rest assured, your variable contains a value of 30.
If you want to be explicit, you can write:
TabStop1 = CCur(30)

-Tom.
Microsoft Access MVP
 
Tom, thank you. I still don't see why this code fails. It gives me a run
time error 424. I have 2 text boxes, TheApplication is the number of
Applications, the default is 1. TheApplicationMoney is the total Money
collected. I run it 'on exit'

Public Sub TheApplication_Exit(Cancel As Integer)
Dim TabStop1 As Currency
Dim TabStop1Cost As Currency
Dim TheApplication As Integer
Me.TheApplication = 1

If Me.TheApplication Is Null Then
Me.TheApplication = 1
Else
Me.TheApplication = Me.TheApplication
TabStop1 = 25#
TabStop1Cost = Me.TheApplication * TabStop1
Me.ApplicationMoney = TabStop1Cost
End If
End Sub
 
You ahve a text box control named "TheApplication" AND a variable named
"TheApplication" declared as an integer??? Very confusing.....

Why do you have this line?

Me.TheApplication = Me.TheApplication


The reason you are getting the error 424, is that you are using "IS NULL" in
the VBA code. "IS NULL" is SQL syntax. In VBA you should use the function
"IsNull()"

'----------------------------------------------
Public Sub TheApplication_Exit(Cancel As Integer)
Dim TabStop1 As Currency
Dim TabStop1Cost As Currency
'Dim TheApplication As Integer '#######
Me.TheApplication = 1

If IsNull(Me.TheApplication) Then '#######
Me.TheApplication = 1
Else
' Me.TheApplication = Me.TheApplication '#######
TabStop1 = 25#
TabStop1Cost = Me.TheApplication * TabStop1
Me.ApplicationMoney = TabStop1Cost
End If
End Sub
'----------------------------------------------


If "Me.TheApplication" is NULL, then the only thing that happens is a 1 is
put in the control "Me.TheApplication". The calculation is not made. You
might want to use

'----------------------------------------------
Public Sub TheApplication_Exit(Cancel As Integer)
Dim TabStop1 As Currency

If IsNull(Me.TheApplication) Then
Me.TheApplication = 1
End If

TabStop1 = 25#
Me.ApplicationMoney = Me.TheApplication * TabStop1
End Sub
'----------------------------------------------


HTH
 
Back
Top