View Full Version : Solved: Checkbox
chungtinhlak
12-09-2008, 11:32 AM
I have a form with textbox that has default value when start, I also have a checkbox that will change these values when I click on it.
how do I make it so that when i check it, it changes, and when i uncheck it, it goes back to the default values when the userform_Initialize()???
thanks
Private Sub CheckBox1_Click()
txtbox1.Value = "I"
txtbox2.Value = "J"
End Sub
Private Sub UserForm_Initialize()
txtbox1.Value = "G"
txtbox2.Value = "H"
End Sub
Bob Phillips
12-09-2008, 11:54 AM
Private Sub CheckBox1_Click()
With Me
If .CheckBox1.Value Then
.txtbox1.Value = "I"
.txtbox2.Value = "J"
Else
.txtbox1.Value = "G"
.txtbox2.Value = "H"
End If
End With
End Sub
Private Sub UserForm_Initialize()
txtbox1.Value = "G"
txtbox2.Value = "H"
End Sub
chungtinhlak
12-09-2008, 12:49 PM
so whenever I do a checkbox*.value, i'm indicating that it's true?
Bob Phillips
12-09-2008, 12:54 PM
No, not exactly. The Checkbox value is a boolean, True or False is its value. As an If test is justing checking for True or False in essence, you don't have to be explicit.
If Checbox1.Value Then
is the same as saying
If Checbox1.Value = True Then
The former is just more logical to my eyes.
chungtinhlak
12-09-2008, 03:34 PM
so can di do a checkbox1.value = true for checked and checkbox1.value= false for unchecked?
Bob Phillips
12-09-2008, 05:22 PM
Yes, but it is better to do
If CheckBox1.Value Then
'and
If Not CheckBox1.Value Then
IMO, as it is more aligned to boolean logic.
chungtinhlak
12-09-2008, 07:17 PM
thanks you
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.