# VBA Code for Text Box Visible Property



## aaghd (Apr 12, 2007)

Hi,

I have a checkbox [ysnDiscontinued]. When it is checked I would like a text box [memReasonForDiscontinuation]to appear. Of course, I only want it to *appear for each record* when the checkbox is or has been checked.

I have placed the following code in the checkbox's "After Update" event property and I have set the text box's "Visible" property to NO.

 
Private Sub ysnDiscontinued_AfterUpdate()

If Me![ysnDiscontinued] = True Then
Me![memReasonForDiscontinuation].Visible = True

Else

Me![memReasonForDiscontinuation].Visible = False
End If
End Sub


When I open the form and look at all records, the textbox is not visible. The textbox only appears on record one after the checkbox has been checked. The problem is that once you check the checkbox, the textbox then appears on all records regardless if the checkbox is checked or not.

Will someone please help me with the correct code and event placement?

Thank you,

aaghd


----------



## OBP (Mar 8, 2005)

I am afraid that it is not your Code or it's Placement that is the problem, it is a characteristic of a Form in "Contiuous Forms" mode.
Any "Unbound" Fields or Labels will show the same data/characteristics for every Record.
So the only way to overcome this is to make it a field in your table and form and then populate it with your Text message when the Tick Box is checked.


----------



## aaghd (Apr 12, 2007)

Thanks for the feedback.

The form is based on an underlying table. The checkbox and the textbox are related to fields in the underlying table.

What else can I tell you to help you help me?

aaghd


----------



## OBP (Mar 8, 2005)

Is it possible to post a zipped copy of the Database as an attachment, or email it to me?


----------



## aaghd (Apr 12, 2007)

Thanks. I would like to e-mail it to you. What is your e-mail address?

aaghd


----------



## OBP (Mar 8, 2005)

aaghd, I have Private Mailed you my email address.


----------



## OBP (Mar 8, 2005)

aaghd, I must have been tired yesterday when I read your post, the problem is not using a Continuous Form as I first thought (without seeing the database). I didn't notice when I first read it, but the problem is the Code that you used. 
Simply change this line

If Me![ysnDiscontinued] = True Then

To

If Me![ysnDiscontinued] = -1 Then

And it works fine.
I discussed this on this post -
http://forums.techguy.org/business-applications/560678-solved-locking-fields-access.html


----------

