error in Date text box

  • Thread starter Thread starter Dean Collins
  • Start date Start date
D

Dean Collins

I am using a textbox to extract the date into my routine.
However, I get an "Invalid use of null" error
When I try to run this even with data entered in the
correct text box. The text box is General date with am
input mask of 99/99/99;

My code is below
Many thanks in advance.
Dean Collins

Private Sub ER_Date_AfterUpdate()
Dim TextBox1 As Date
Dim TextBox2 As Integer
Forms!Main_Edited!ER_Yr_1.SetFocus
TextBox1 = Forms!Main_Edited!Yr_1
Forms!Main_Edited!EnrolDay2002 = 1
TextBox2 = Forms!Main_Edited!EnrolDay2002
Debug.Print TextBox1
Debug.Print TextBox2
End Sub
 
Hi,


Only a Variant (data type) can hold a Null. It seems that Forms!Main_Edited!Yr_1 hold nothing,
so, has the value NULL. You can't store a Null into a Date, or into an Integer. Maybe you can try
to change the line of code to

TextBox1 = Nz(Forms!Main_Edited!Yr_1, Now( ) )


which will take Now( ) for the value, if there is nothing in Forms!Main_Edited!Yr_1

Hoping it may help,
Vanderghast, Access MVP
 
Thank you for replying,

However, the problem is that my variable is holding a null
value instead of the date entered in the text box (Forms!
Main_Edited!Yr_1). Do you know why this is happening?

Dean Collins




-----Original Message-----
Hi,


Only a Variant (data type) can hold a Null. It seems
that Forms!Main_Edited!Yr_1 hold nothing,
so, has the value NULL. You can't store a Null into a
Date, or into an Integer. Maybe you can try
 
Hi,


Your variable? You have a variable name that strangely look very like a control name. Can you
use a variable name that will be less confusing, like


Dim myVar As Date
myVar=Nz( ... , ... )


and then, test what myVar hold ?


Vanderghast, Access MVP
 
Back
Top