Can I make areas on a form hidden, unless...

G

GD

I have 2 check boxes on my form. Ideally, I'd like for certain text boxes to
remain hidden from sight on the form, unless the appropriate check box is
checked. Is it possible to do this? If not with check boxes, is there an
alternative?

Thanks for your time!!
 
R

Roger Carlson

Yes, it is possible to do. You'll have to use some code though.

In the After Update event of your check box, put something like this:

If Checkbox1 = True Then
Text1.Visible = True
Else
Text1.Visible = False
End If

You will also want to add this code to your On Current event of the form so
it will set these values when you move from record to record in your form.

--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L
 
C

Carl Rapson

In the Click event of the checkbox, put code such as:

Me.txtTextBox.Visible = Me.chkCheckBox

This will set the Visible property of the text box to True or False,
depending on the "value" of the checkbox (checked is True, unchecked is
False). If you are navigating between records and want to do the same thing
when a record is displayed, put similar code in the form's Current event.

Carl Rapson
 
G

GD

Thanks, Roger. But I still have a problem. The combo box has disappeared,
but it doesn't reappear when the check box is checked. Does the check box
have to be bound to a table? Because it is currently unbound, but won't stay
that way. Code is:

Private Sub Combo206_AfterUpdate()
If Check195 = True Then
Combo206.Visible = True
Else
Combo206.Visible = False
End If

End Sub

Private Sub Form_Current()
If Check195 = True Then
Combo206.Visible = True
Else
Combo206.Visible = False
End If

End Sub
 
R

Roger Carlson

Two things:

First, the code should go behind the Checkbox, not the ComboBox. So it
would be:

Private Sub Check195_AfterUpdate()
If Check195 = True Then
combo206.Visible = True
Else
combo206.Visible = False
End If
End Sub

Private Sub Form_Current()
If Check195 = True Then
combo206.Visible = True
Else
combo206.Visible = False
End If
End Sub

Secondly, yes, I was assuming a bound checkbox. The code behind the
Checkbox will work with an unbound box, but the OnCurrent code won't work
properly.

By the way, Carl's code will work just as well and is shorter.

Private Sub Check195_AfterUpdate()
Me.combo206.Visible = Me.Check195
End Sub

Private Sub Form_Current()
Me.combo206.Visible = Me.Check195
End Sub

I use my way because I think it is easier to understand for someone else to
modify later. Personal preference.

--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L
 
G

GD

Works great!! Thanks!
--
GD


Roger Carlson said:
Two things:

First, the code should go behind the Checkbox, not the ComboBox. So it
would be:

Private Sub Check195_AfterUpdate()
If Check195 = True Then
combo206.Visible = True
Else
combo206.Visible = False
End If
End Sub

Private Sub Form_Current()
If Check195 = True Then
combo206.Visible = True
Else
combo206.Visible = False
End If
End Sub

Secondly, yes, I was assuming a bound checkbox. The code behind the
Checkbox will work with an unbound box, but the OnCurrent code won't work
properly.

By the way, Carl's code will work just as well and is shorter.

Private Sub Check195_AfterUpdate()
Me.combo206.Visible = Me.Check195
End Sub

Private Sub Form_Current()
Me.combo206.Visible = Me.Check195
End Sub

I use my way because I think it is easier to understand for someone else to
modify later. Personal preference.

--
--Roger Carlson
MS Access MVP
Access Database Samples: www.rogersaccesslibrary.com
Want answers to your Access questions in your Email?
Free subscription:
http://peach.ease.lsoft.com/scripts/wa.exe?SUBED1=ACCESS-L
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top