View Full Version : Issues with Null values and .visible


laxster
05-05-2010, 06:31 AM
Hi,

I wrote some VBA code which looks at a value in a textbox, and if it's null it will display a blank line.

However, it doesn't work properly with null values, only if I substitute actual values, which I want to avoid if at all possible.

Here's the code:
If Me.Year = Null Then
Me.Year.Visible = False
Me.lnYear.Visible = True
Else
Me.lnYear.Visible = False
End If

Are there special considerations I should make with null values or a workaround? Again, it works with anything other than a null value, but a null value is what I need it to work for.

Thanks for looking at this! :)

Kryst51
05-05-2010, 06:33 AM
Hi,

I wrote some VBA code which looks at a value in a textbox, and if it's null it will display a blank line.

However, it doesn't work properly with null values, only if I substitute actual values, which I want to avoid if at all possible.

Here's the code:
If Me.Year = Null Then
Me.Year.Visible = False
Me.lnYear.Visible = True
Else
Me.lnYear.Visible = False
End If

Are there special considerations I should make with null values or a workaround? Again, it works with anything other than a null value, but a null value is what I need it to work for.

Thanks for looking at this! :)

I know that null doesn't work well that way.

Try:

If Nz(Me.Year) Then
Me.Year.Visible = False
Me.lnYear.Visible = True
Else
Me.lnYear.Visible = False
End If

laxster
05-05-2010, 06:43 AM
It still seems to be doing the same thing. :( Is there a way it will allow me to use the nz function to specify a value, and then use that value to allow the blank line to display and make the text box invisible?

Kryst51
05-05-2010, 06:44 AM
It still seems to be doing the same thing. :( Is there a way it will allow me to use the nz function to specify a value, and then use that value to allow the blank line to display and make the text box invisible?

Yeah Something like: Nz(Me.Year,YourValueHere)

laxster
05-05-2010, 07:01 AM
I am still having issues with it -- I put that right in the code for the OnFormat event, and it refuses to do it properly.

Am I maybe missing something, or is there a better way of doing this?

Kryst51
05-05-2010, 07:03 AM
I am still having issues with it -- I put that right in the code for the OnFormat event, and it refuses to do it properly.

Am I maybe missing something, or is there a better way of doing this?

Can you post your db? That was what jumped out at me... I don't know enough, to know what else it could be without playing with is myself.

Brianwarnock
05-05-2010, 07:56 AM
If Me.Year = Null Then

change to

If isnull(Me.Year) Then

Brian

BTW you must display a value with NZ only in the DG of queries does it default to 0.