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 strongm 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.

scottintexas

Programmer
Feb 27, 2006
12
US
I am using Access 2007. I am taking field values from a form and putting them into the properties of a class object. Some values can be null, but I get the error "Invalid use of null..." because the property is expecting a value. How do I tell a property that null is ok?

For example I have this property

Public Property Let ShipperSuite(ByVal vNewValue As String)
shipperAdd2 = vNewValue
End Property

in my code I have;

Order.ShipperSuite=Me.ShipSuite 'which is a null text field
To be clear, I do not want to assign null, I just don't care if the field is empty. I really don't want to go through each property and check to see if the value is null and turn it into an empty string.

ScottInTexas
It's probably as hard as it looks.
 
OK. Here is my answer. I just thought there may be a way to make text boxes equal to "" instead of Null when empty. Apparently not. So when assigning values to a table or, in my case, a class I used clsOrder.Property=IIF(IsNull(MyFieldName),"",MyFiledName). It avoids the error nicely.

ScottInTexas
It's probably as hard as it looks.
 
Glad you solved it.

After pondering the riddle (for many years I might add) I finally got the answer (inadvertently through a movie): "If a tree falls in the forest and no one is around, does it make a sound?"
 
You may also try:
[tt]
clsOrder.Property = MyFiledName [blue]& ""[/blue]
[/tt]or
[tt]Public Property Let ShipperSuite(ByVal vNewValue As String)
shipperAdd2 = vNewValue [blue]& ""[/blue]
End Property
[/tt]

Have fun.

---- Andy

A bus station is where a bus stops. A train station is where a train stops. On my desk, I have a work station.
 
I should have come back to this sooner, sorry. I solved the issue by using IIF statements just so I could move on. I was hoping there was some sort of setting which says If anything is null set it to "". But that is approaching the "Read my mind and do it" button. We just aren't there yet.
Code:
[indent]Order.ShipperAddress2=IIf(IsNull(Me.txtShipperAddressSt2), "", Me.txtShipperAddressSt2)[/indent]

Problem solved. Just more typing.

ScottInTexas
It's probably as hard as it looks.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top