How to test for Null

K

Karen Hagerman

I am textbox.oldvalue to save the previous value in a textbox so I can have a history of edits to a record. If the record is, however, a new record, the Null value of .oldvalue is generating runtime errors:

The following If-Then-Else comes up with a runtime error of '94': Invalid use of Null

If txtName.Oldvalue = Null Then
NameOldValue = "New Record"
Else
NameOldValue = txtName.OldValue
End If

This other If-Then-Else comes up with a runtime error of '424': Object Required

If txtName.Oldvalue is Null Then
NameOldValue = "New Record"
Else
NameOldValue = txtName.OldValue
End If

How can I test for Null without generating a runtime error OR is there a better test to apply if it is a new record that is being populated? Any help will be appreciated.
Karen
 
R

RobFMS

Karen

Try: If IsNull(Me.txtName.Oldvalue) Then


--

Rob

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Problems with your database? Need to upgrade your application?
Contact the FMS Professional Solutions Group: www.fmsinc.com/consulting

Need a Book Recommendation?
www.fmsinc.com/toplevel/books.htm

Need software tools for Access, VB or .NET?
http://www.fmsinc.com
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-



I am textbox.oldvalue to save the previous value in a textbox so I can have a history of edits to a record. If the record is, however, a new record, the Null value of .oldvalue is generating runtime errors:

The following If-Then-Else comes up with a runtime error of '94': Invalid use of Null

If txtName.Oldvalue = Null Then
NameOldValue = "New Record"
Else
NameOldValue = txtName.OldValue
End If

This other If-Then-Else comes up with a runtime error of '424': Object Required

If txtName.Oldvalue is Null Then
NameOldValue = "New Record"
Else
NameOldValue = txtName.OldValue
End If

How can I test for Null without generating a runtime error OR is there a better test to apply if it is a new record that is being populated? Any help will be appreciated.
Karen
 
K

Karen Hagerman

Thank you so much. I am still learning VBA and who would have thought? Works great, thanks again.

Karen

Karen

Try: If IsNull(Me.txtName.Oldvalue) Then


--

Rob

-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
Problems with your database? Need to upgrade your application?
Contact the FMS Professional Solutions Group: www.fmsinc.com/consulting
 
C

Chris Strug

Karen,

You may also find the "nz()" function useful. This tests for a null and
replaces it with the value of your choice.

Chris


Thank you so much. I am still learning VBA and who would have thought?
Works great, thanks again.

Karen
 
K

Karen Hagerman

That is very cool, I hadn't seen that particular function at all, thanks
very much.

Karen
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top