Null Values Causing Errors

  • Thread starter Thread starter John Ortt
  • Start date Start date
J

John Ortt

I am trying to use the following code to take a date value from a form:

If Me.Controls(WSNumber).Value = Null Then WSVal = 0
Else WSVal = Me.Controls(WSNumber).Value

The problem arrises when you scroll onto a blank record as it throws up an
error
(I believe due to the null value).

Does anybody have any suggestions on how I can overcome this please?

Thanks,

John
 
John,

u cant test to see if something is null by the way you are writing the code
below. Try changing it to:

If IsNull(Me.Controls(WSNumber)) Then
WSVal = 0
Else
WSVal = Me.Controls(WSNumber)
End If

An even easier way to achive what you are looking for is to use the nz
function. This will test for a null value and then replace it with another
value, as specified after the ','.

WSVal = nz(Me.Controls(WSNumber), 0)

HTH,

Neil.

Ho
 
WSVal = nz(Me.Controls(WSNumber), 0)

Thanks Neil, this is exactly what I wanted....

I did try the Nz method but I forgot to put in the ",0" alternative so thats
prob where I went wrong.

Thanks again,

John.
 
Hi John,

Yes, that is probably where you went wrong :-)

It is quiet handy. I know u are working with numbers in this case, but you
can place anything after the , to be displayed instead of nothing. A
Required textbox for example could have the following:

Me.RequiredTextBox = nz(Me.SomeControlsValue, "This is a required
field - please complete")

Neil.
 
Back
Top