Null

  • Thread starter Thread starter Scott Matheny
  • Start date Start date
S

Scott Matheny

I'm trying to write code in an afterupdate that changes a
property of another part of the form. However, what I have
is not working and I suspect it is the Null call out.
Please give me any advice; here is my code:

Sub Combo60_AfterUpdate()

If Text87.Value Or Text89.Value = Null Then
TabCtl76.Visible = False
Else
TabCtl76.Visible = True
End If

End Sub

What happens in my form is after you select a value from
Combo60, it relays values into Text 87 and Text89. I want
another section of the form to stay invisible (I also have
code in the Form_load() to make that same part invisible
at the load) if either text box doesn't have a value.

I tried placing msgbox text87.value into the Form_load(),
and it said misuse of Null. FFNNNNRRRGGGHHHH

Thanks in advance,
-Scott M.
 
You can't compare to null.

Use the IsNull function...

If IsNull(Text87) or IsNull(Text89) Then
..
..
..




Rick B


I'm trying to write code in an afterupdate that changes a
property of another part of the form. However, what I have
is not working and I suspect it is the Null call out.
Please give me any advice; here is my code:

Sub Combo60_AfterUpdate()

If Text87.Value Or Text89.Value = Null Then
TabCtl76.Visible = False
Else
TabCtl76.Visible = True
End If

End Sub

What happens in my form is after you select a value from
Combo60, it relays values into Text 87 and Text89. I want
another section of the form to stay invisible (I also have
code in the Form_load() to make that same part invisible
at the load) if either text box doesn't have a value.

I tried placing msgbox text87.value into the Form_load(),
and it said misuse of Null. FFNNNNRRRGGGHHHH

Thanks in advance,
-Scott M.
 
Try:
Sub Combo60_AfterUpdate()

If IsNull(Me.Text87) Or IsNull(Me.Text89) Then
Me.TabCtl76.Visible = False
Else
Me.TabCtl76.Visible = True
End If

End Sub

Sandy
 
Awesome, that worked like a charm :)
I used Text87.value inside IsNull() because I'm not really
sure what Me. means. If you could explain this, that'd be
great.

Thanks a million,
-Scott M.
 
You have to use the IsNull function to compare a value to null:

if isnull(me.Text87) then
TabCtl76.Visible = False
Else
TabCtl76.Visible = True
End If

A shorter way of doing the same thing is:

me.TabCtl76.Visible = not isnull(me.text87)

Note that while it is not required to prefix a reference to a control with
the "me" keyword it is definately preferred since it makes a distinction
between VBA variables and property, control or field references.
 
Sandra Daigls response explained it perfectly:

Note that while it is not required to prefix a reference to a control with
the "me" keyword it is definately preferred since it makes a distinction
between VBA variables and property, control or field references.

Sandy
 
Back
Top