Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations sizbut on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

if checkbox = true insert textbox

Status
Not open for further replies.

bruch04

Technical User
Mar 12, 2004
9
US
Hi. I have a form, and on the form is a checkbox for "if you have a comment...". If the user has a comment and checks the checkbox, I want a textbox to appear underneath so the user can input their comments. Otherwise, I don't want to waste space on the form with empty textboxes where they have no comments. Any ideas?

Thanks
 
Hi,

Take a look at the Visible property

Skip,

[glasses] [red]Be advised:[/red] The dyslexic, agnostic, insomniac, lays awake all night wondering...
"Is there really a DOG?" [tongue]
 
Well, it's not that I just don't want it available to write in if they don't have any comments, it's that I don't want to waste space on the form. If visible is set to false, it is still taking up space on the form even though you can't see it.

PS...I forgot to mention, this is for ms word forms. I find word macros much less intuitive than excel macros....
 
Is it? Hmmmmmmmmmmm.

Only if YOU give it space on the form.

Skip,

[glasses] [red]Be advised:[/red] The dyslexic, agnostic, insomniac, lays awake all night wondering...
"Is there really a DOG?" [tongue]
 
Sounds like you need to pop up a new form and pass the entered text back to the first.

It is possible to change the size of a form, add or delete items and move objects around programatically, but it would be a PITA.
 
It's eseentally the same form with one exception. Create another form just for the addition of a textbox?
Code:
Private Sub CheckBox1_Click()
    If CheckBox1.Value Then
        TextBox1.Visible = True
        UserForm1.Height = 150
    Else
        TextBox1.Visible = False
        UserForm1.Height = 50
    End If
End Sub

Skip,

[glasses] [red]Be advised:[/red] The dyslexic, agnostic, insomniac, lays awake all night wondering...
"Is there really a DOG?" [tongue]
 
We are confusing UserForms with "forms" again.

Let's please clarify.

Is this a UserForm, or a "form" IN a document? Is the checkbox a formfield or ActiveX control IN the document, or a checkbox on a UserForm?

From the post, I am gathering it is a checkbox in the document - this is NOT a UserForm. In which case, Skip's code does not apply. The .Visible property does not apply to textboxes (either ActiveX controls OR formFields) in a document. The question is: is the textbox a FormField textbox or an ActiveX textbox?

If I am correct (it is NOT a UserForm), the solution is to use an ActiveX textbox. While it does not have a .Visible property, it DOES have a resizing capability. In other words, you can make logic like:

If checkbox value is TRUE (checked)
textbox height = 200 (or whatever fits for you)
textbox width = 300 (or whatever fits for you)
Else ' checkbox value is FALSE (unchecked)
textbox height = 2
textbox width = 2

You will have to experiment a little bit. Depending on screen resolution a line such as Textbox1.Height = 1 may actually return something like 1.46. So any logic that explicitly checks for "1" may fail. Better to something like > 0 AND < 2. same goes for Width.

Essentially, you can shrink the textbox to much much less than a single character. Setting the border to nothing make the textbox so tiny, that is for all practical purposes it is invisible. It can be resized back up for user input at your command.

Code for resizing should be placed in the ThisDocument module. It can be run from other module, but it is so much easy in ThisDocument, because all the events for ActiveX controls are accessible through normal dropdown menus.

Gerry
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top