Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Invalid Use of Null

Status
Not open for further replies.

Telsa

Programmer
Jun 20, 2000
393
US
Why do I get Invalid Use of Null with this code?

Me.ReleaseDate.DefaultValue = Me.ReleaseDate

I'm trying to use newly saved record as default for next new record. The fields in question are date fields. If it is empty, I get the error of Invalid use of Null. How do I have it skip that field without error if it is empty?

Mary :eek:)
 
This is because the default value of a date field is
(thankfully) 'null' with Jet databases and MSSQL as well.

... and in Visual Basic and VBA, (and many other languages) through a decision made by the language creators and the ANSI commitees that contributed to language standards many years ago, any attempt to assign the value 'null' to a variable results in a runtime error.

Take my word for it, it's a good thing. Programmers are left to test for the 'null' value before attempting to make assignments where null may be present, like in the example that you have included with your question.

...code like this is typically is used to eliminate that problem.
If Not IsNull(Me.ReleaseDate) then
Me!yourDateVariable = Me.ReleaseDate
else
'Release date is 'null' so take some other course of action. Attempt to assign 'null' generates Error 94
End If

Hope this helps.

 
You know, I tried that and still got an error before. I'll try it again... I must have done a typo on my coding...

Thanks!

Mary :eek:)
 
Okay, it runs without errors, but I capture no date if it exists!

Thoughts??????

Thanks!

Mary :eek:)
 
This guy right here seems to be the problem.
[red]Me.ReleaseDate.DefaultValue[/red] = Me.ReleaseDate
If this is a text box on a form (bound or unbound) the syntax is thus;[/i]

Me![ReleaseDate] = "New Value"
..so that

Me![ReleaseDate] = Me![text2]
assigns the value of text2 to text 1

If you want to change the Propery of [ReleaseDate] things are a little different. The property is 'persisted' in the property collection of that Form in the database. If you are simply assigning the value then use the code above, of course testing for 'null' before attempting the assignment.

have Fun !


 
How would you assign the value to be null? I've had trouble in the past where the user has entered a date in a table field, but then wanted to delete that date. How would you set the date back to null again? I haven't really tinkered with it too much. Thanks!
 
I have the same question, how would I set the value of Date back to Null as though the field had never been entered into ? Bob Schmid
bob_schmid@hmis.org
330-746-1010 ext. 1347
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top