if statement help

  • Thread starter Thread starter Dave Elliott
  • Start date Start date
D

Dave Elliott

text1000 control source is =[NameB].[Column](10)
i.e. it will be 55 or else 65
label is not showing up ?


If [Text1000] = 55 Then
Lbl6.Visible = True
Else:
Lbl6.Visible = False
End If
 
I think it was mentioned before that the "else" statement should not have a
colon --- it's being treated as a line label and not as an "else" !
 
irregardless, the code does not work without the else, what can I do to fix
this?


Bob Howard said:
I think it was mentioned before that the "else" statement should not have a
colon --- it's being treated as a line label and not as an "else" !


Dave Elliott said:
text1000 control source is =[NameB].[Column](10)
i.e. it will be 55 or else 65
label is not showing up ?


If [Text1000] = 55 Then
Lbl6.Visible = True
Else:
Lbl6.Visible = False
End If
 
Where did you place this code? Also, the control source of the textbox you
are trying to get a value from is a calculated textbox. It may take a second
or two for the textbox to update. The code may have already run at that
point. Instead, use the equation you have in the control source in your code
also. This will get rid of the potential timing problem.

Example:
If Me.NameB.Column(10) = 55 Then
Lbl6.Visible = True
Else
Lbl6.Visible = False
End If

If you wanted to shorten this, you could take advantage of the fact that the
result you are looking for is Visible either True or False and that the
result of your test in the If statement is also either True or False. That
would allow you to change the above to

Lbl6.Visible = (Me.NameB.Column(10) = 55)

Use whichever is less typing for you. If you are changing multiple controls
in the If statement, the If statement may be less typing.
 
Dave,

The code is probably working exactly as you wrote it. Since the Else: (with
the colon) is seen as a label, it is ignored it this context, so what is
happening is if the value of [text100] = 55, lbl6 becomes visible then
immediately goes invisible. Try stepping through it in debug mode and you
will see that happen. All you really need to do is remove the colon.

Dave Elliott said:
irregardless, the code does not work without the else, what can I do to fix
this?


Bob Howard said:
I think it was mentioned before that the "else" statement should not have a
colon --- it's being treated as a line label and not as an "else" !


Dave Elliott said:
text1000 control source is =[NameB].[Column](10)
i.e. it will be 55 or else 65
label is not showing up ?


If [Text1000] = 55 Then
Lbl6.Visible = True
Else:
Lbl6.Visible = False
End If
 
Back
Top