enable/disable fields with checkbutton

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

Guest

Hi everybody
This is my first time using access 2003, I designed a form in which there is
a checkbutton that, by default should not be checked.
The user will check it then additional text fields will appear.
How can I do this ?
 
To be clear you should refer to it as a check box, which is the standard
terminology.
Short answer: In the check box After Update event (and in the form's
Current event) you can make the text boxes visible with something like the
following:

If Me.chkYourCheckBox = True Then
Me.txtTextBox1.Visible = True
Me.txtTextBox2.Visible = True
Else
Me.txtTextBox1.Visible = False
Me.txtTextBox2.Visible = False
End If

A few more details: Click the check box to select it, then click View >
Properties (or right click it and select Properties). Click the Events tab,
then click next to After Update. Click the three dots, click Code Builder,
and click OK. In the window that opens the cursor should be blinking
between a line that starts Private Sub and one that reads End Sub. Put the
code there, *substituting the actual names for your check box and text
boxes*.

A refinement: With the form open in design view, click View > Code, or
click the Code button on the toolbar. Click Insert > Procedure. Give the
procedure a name such as ShowBoxes, and click OK. Enter the code as
described. In the check box After Update event and in the form's Open
event, instead of putting the code you can call the code by the name you
just gave it:
Call ShowBoxes
 
Your users might find it less disconcerting if the additional text fields
don't blink in and out of existence. You could set them to "disabled" to
start with, and enable them if the checkbox is checked.

Bruce offered code to make them visible/invisible. A small variation, with
"enabled", might be:

Dim blnChecked as Boolean
...
blnChecked = Me.chkYourCheckBox

Me.txtYourFirstTextBox.Enabled = blnChecked
Me.txtYourSecondTextBox.Enabled = blnChecked
...

The advantage to this approach shows up if you have more than a couple
textboxes to manipulate.

--
Regards

Jeff Boyce
Microsoft Office/Access MVP


Microsoft IT Academy Program Mentor
http://microsoftitacademy.com/

Microsoft Registered Partner
https://partner.microsoft.com/
 
I need to remember that approach. It's much tidier in many situations than
the If statement.
 
Bruce

As mentioned, the real advantage shows up when there's more than just one or
two fields to manipulate. Not having to repeatedly evaluate the condition
of the checkbox (or any other "trigger") saves Access a bit of work. Every
electron counts! (but some count more than others...<g>)

--
Regards

Jeff Boyce
Microsoft Office/Access MVP


Microsoft IT Academy Program Mentor
http://microsoftitacademy.com/

Microsoft Registered Partner
https://partner.microsoft.com/
 

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

Back
Top