Enable a Textbox when a Checkbox is checked.

Botje

New Member
Joined
Aug 23, 2011
Messages
48
Hej there.

I found multiple things on google/ on this forum like:
http://www.mrexcel.com/forum/showthread.php?t=370641&highlight=Checkbox+Enable%2FDisable+txtBox1

http://www.google.nl/search?q=enabl...x+excel+vba&hl=nl&source=hp&aq=f&aqi=&aql=&oq=

( Did change it to my own text/checkbox name. )
Code:
Private Sub chkHomeNumber_Click()
    If chkHomeNumber Then
        TextBoxHomeNumberSTD.Enabled = True
        TextBoxMain.Enabled = True
    Else
        TextBoxHomeNumberSTD.Enabled = False
        TextBoxMain.Enabled = False
    End If
End Sub
 
Private Sub chkExtension_Change()
If chkExtension = True Then
ActiveCell.Offset(0, 15).Value = "Yes"
Else
ActiveCell.Offset(0, 15).Value = "NO"
 
End If
 
If chkExtension = True Then
txtExtDate.Enabled = True
Else
chkExtension.Enabled = False
txtExtDate.Enabled = False
End If
End Sub

But I just cannot open my form.. without my "Textbox"( Textbox = named "Textanders" being invisible/gray..)
It is visible and can type in it what ever code I use. What i dont want unless the CheckBox is checked.

Where should i add it? Or what should i change in my code?

Code:
Private Sub CheckAnders_Click()
    If checkAnders Then
        TextAnders.Enabled = True
    Else
        TextAnders.Enabled = False
        End If
End Sub
 
Private Sub cmdinvullen_Click()
    If Me.TxtNaam.Value = "" Then
    MsgBox "Vul alsjeblieft je naam in.", vbExclamation, "Invulformulier Ideeën Bord"
    Me.TxtNaam.SetFocus
    Exit Sub
End If
    If Me.txtidee.Value = "" Then
    MsgBox "Vul alsjeblieft je idee in.", vbExclamation, "Invulformulier Ideeën Bord"
    Me.txtidee.SetFocus
    Exit Sub
End If
    If Me.ComboBox1.Value = "" Then
    MsgBox "Vul alsjeblieft je team in.", vbExclamation, "Invulformulier Ideeën Bord"
    Me.ComboBox1.SetFocus
    Exit Sub
End If
    If Datum.Value = "" Then
    MsgBox "Vul alsjeblieft een datum in."
    Exit Sub
End If
    If Not IsDate(Datum.Value) Then
    MsgBox "Ongeldige datum ingevoerd."
    Exit Sub
End If
If DateValue(Datum.Value) <= Date Then
    MsgBox "Datum dient in de toekomst te liggen."
    Exit Sub
End If
Dim Resp As Variant
    Resp = MsgBox("Je hebt de volgende informatie ingevoerd, klopt dit? " & vbNewLine & "Naam  :        " & Me.TxtNaam.Value & vbNewLine & "Team  :        " & Me.ComboBox1.Value & vbNewLine & "Idee    :        " & Me.txtidee.Value, vbYesNo + vbQuestion)
    If Resp = vbNo Then
                    Exit Sub
    Else
        MsgBox "Idee ingevoerd!"
 
End If
RowCount = Worksheets("Archief").Range("B1").CurrentRegion.Rows.Count
With Worksheets("Archief").Range("B1")
.Offset(RowCount, 14).Value = Me.TxtNaam.Value
.Offset(RowCount, 0).Value = Me.txtidee.Value
.Offset(RowCount, 15).Value = Me.ComboBox1.Value
If Me.chkTijd.Value = True Then
.Offset(RowCount, 19).Value = "X"
Else
.Offset(RowCount, 19).Value = ""
End If
If Me.chkGeld.Value = True Then
.Offset(RowCount, 20).Value = "X"
Else
.Offset(RowCount, 20).Value = ""
End If
If Me.chkCollegas.Value = True Then
.Offset(RowCount, 21).Value = "X"
Else
.Offset(RowCount, 21).Value = ""
End If
If Me.chkToestemming.Value = True Then
.Offset(RowCount, 22).Value = "X"
Else
.Offset(RowCount, 22).Value = ""
End If
If Me.chkRuimte.Value = True Then
.Offset(RowCount, 23).Value = "X"
Else
.Offset(RowCount, 23).Value = ""
End If
If Me.checkAnders.Value = True Then
.Offset(RowCount, 24).Value = "X"
Else
.Offset(RowCount, 24).Value = ""
End If
If Me.chkAchmeaVitale.Value = True Then
.Offset(RowCount, 1).Value = "X"
Else
.Offset(RowCount, 1).Value = ""
End If
If Me.chkKeuringen.Value = True Then
.Offset(RowCount, 2).Value = "X"
Else
.Offset(RowCount, 2).Value = ""
End If
If Me.chkKlantenservice.Value = True Then
.Offset(RowCount, 3).Value = "X"
Else
.Offset(RowCount, 3).Value = ""
End If
If Me.chkFrontoffice.Value = True Then
.Offset(RowCount, 4).Value = "X"
Else
.Offset(RowCount, 4).Value = ""
End If
If Me.chkExoten.Value = True Then
.Offset(RowCount, 5).Value = "X"
Else
.Offset(RowCount, 5).Value = ""
End If
If Me.chkMKB.Value = True Then
.Offset(RowCount, 6).Value = "X"
Else
.Offset(RowCount, 6).Value = ""
End If
If Me.chkDAM.Value = True Then
.Offset(RowCount, 7).Value = "X"
Else
.Offset(RowCount, 7).Value = ""
End If
If Me.chkBA.Value = True Then
.Offset(RowCount, 8).Value = "X"
Else
.Offset(RowCount, 8).Value = ""
End If
If Me.chkRAM.Value = True Then
.Offset(RowCount, 9).Value = "X"
Else
.Offset(RowCount, 9).Value = ""
End If
If Me.chkSAM.Value = True Then
.Offset(RowCount, 10).Value = "X"
Else
.Offset(RowCount, 10).Value = ""
End If
If Me.chkAMI.Value = True Then
.Offset(RowCount, 11).Value = "X"
Else
.Offset(RowCount, 11).Value = ""
End If
If Me.chkGMAT5.Value = True Then
.Offset(RowCount, 12).Value = "X"
Else
.Offset(RowCount, 12).Value = ""
End If
If Me.chkICO.Value = True Then
.Offset(RowCount, 13).Value = "X"
Else
.Offset(RowCount, 13).Value = ""
.Offset(RowCount, 16).Value = Format(Now, "dd/mm/yyyy hh:nn")
End If
.Offset(RowCount, 17).Value = DateValue(Datum.Text)
End With
    Unload Me
End Sub
Private Sub cmdsluiten_Click()
    Unload Me
End Sub
Private Sub UserForm_Click()
End Sub
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
You could use the Visible property if you really only want it shown when the checkbox is checked. But as a rule of thumb, that goes against current UI guidelines.

Are you sure you are not using checkAnders as a variable somewhere, because from the code
Code:
Private Sub CheckAnders_Click()
    If checkAnders Then
        TextAnders.Enabled = True
    Else
        TextAnders.Enabled = False
    End If
End Sub
I find it strange you have CheckAnders in the procedure name and checkAnders in the body. I would expect VBA to autocorrect the first capital...

I tested similar code here, and it works fine...
 
Upvote 0
You could use the Visible property if you really only want it shown when the checkbox is checked. But as a rule of thumb, that goes against current UI guidelines.

Are you sure you are not using checkAnders as a variable somewhere, because from the code
Code:
Private Sub CheckAnders_Click()
    If checkAnders Then
        TextAnders.Enabled = True
    Else
        TextAnders.Enabled = False
    End If
End Sub
I find it strange you have CheckAnders in the procedure name and checkAnders in the body. I would expect VBA to autocorrect the first capital...

I tested similar code here, and it works fine...

So what you are saying here is that i should have all my words exactly the same! thanks for the info!
 
Upvote 0
VBA should take care of that for you automatically...
The fact I see checkAnders in an event handler for CheckAnders throws up a red flag for me... Probably if you change the lowercase to uppercase, VBA changes it back again, right?

rightclick the checkAnders word and select Definition... where does that jump to?
 
Upvote 0
VBA should take care of that for you automatically...
The fact I see checkAnders in an event handler for CheckAnders throws up a red flag for me... Probably if you change the lowercase to uppercase, VBA changes it back again, right?

rightclick the checkAnders word and select Definition... where does that jump to?


Nope, it works now! All capital did work!
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,971
Members
452,371
Latest member
Frana

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top