What event to change a controls visible property

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hello

I am trying to set a controls visible property depending on the contents of
a text box.

I have the following simple If/Else statement:

If Me.txtAnswer = "multiple" Then
Me.txtAddAnswer.Visible = yes
Else
Me.txtAddAnswer.Visible = no
End If

Will this code work ? What Event would this go in. Itried several an can not
get it to work proberly.

Thanks for your help
Brian
 
The code should go into the AfterUpdate eventhandler of
txtAnswer.
The Visible property should be set to True or False not Yes
or No.

Hope This Helps
Gerald Stanley MCSD
 
Hello

I am trying to set a controls visible property depending on the contents of
a text box.

I have the following simple If/Else statement:

If Me.txtAnswer = "multiple" Then
Me.txtAddAnswer.Visible = yes
Else
Me.txtAddAnswer.Visible = no
End If

Will this code work ? What Event would this go in. Itried several an can not
get it to work proberly.

Thanks for your help
Brian

1) You can shorten your code to one line:

Me!txtAddAnswer.Visible = Me!txtAnswer = "multiple"

2) Where you place the line depends upon what you are doing.

If txtAnswer cannot be changed by the user, place the code in the
form's Current event only.

If txtAnswer can be changed by the user, place the code in the
txtAnswer AfterUpdate event AND in the Form's Current event.
 
BT said:
Hello

I am trying to set a controls visible property depending on the contents of
a text box.

I have the following simple If/Else statement:

If Me.txtAnswer = "multiple" Then
Me.txtAddAnswer.Visible = yes
Else
Me.txtAddAnswer.Visible = no
End If

Will this code work ? What Event would this go in. Itried several an can not
get it to work proberly.


Typically the code goes into both the text box's AfterUpdate
event as well as the form's Current event.

That code should work if you change the Yes to True and the
no to False, but it could be shorter:
Me.txtAddAnswer.Visible = (Me.txtAnswer = "multiple")
 
Back
Top