Written By TheVBProgramer.
The checkbox acts as a "toggle" control: if it's on, clicking it turns it off; if it's off, clicking it turns it on. Unlike the option button, the operation of each checkbox on a form or frame is independent of all other checkboxes; changing the status of one does not affect other checkboxes.
The program can read or set the status of a checkbox with the Value property (which is the default property of the checkbox). The Value property of a checkbox is of the Integer type. A value of 0 means "off", a value of 1 means "on". You can use the VB constants vbUnchecked or vbChecked for 0 or 1, respectively.
Following is a checkbox demo. The form contains 6 checkboxes within a frame, named chkHobby1, chkHobby2, … chkHobby6. The form also contains a command button called cmdOK and a label called lblInfo. This is the form at design time:

The code behind the OK button is:
Private Sub cmdOK_Click()
Dim strInfo As String
strInfo = "Items selected:"
If chkHobby1 = vbChecked Then strInfo = strInfo & " aerobics"
If chkHobby2 = vbChecked Then strInfo = strInfo & " reading"
If chkHobby3 = vbChecked Then strInfo = strInfo & " travel"
If chkHobby4 = vbChecked Then strInfo = strInfo & " movies"
If chkHobby5 = vbChecked Then strInfo = strInfo & " computers"
If chkHobby6 = vbChecked Then strInfo = strInfo & " sports"
lblInfo = strInfo
End Sub
Sample run:

Download the VB project code for the example above here.
Checkbox code using ADODC Connection
Hi, what is the code for checkbox connected in a database (ADODC CONNECTION)
Thanks
hi,do you means when checkbox
hi,do you means when checkbox checked, get value from database?
If chkBox1.value = 1 Then
adoYourAdo.Recordset.Close
adoYourAdo.Recordset.Source = "select * from yourTable "
adoYourAdo.Recordset.Open
adoYourAdo.Recordset.Requery
End If
End Sub
menggunakan Check Box pada listview di VB 6.0
Bagaimana source code untuk menggunakan check box dalam listview pada VB 6.0, yang akan digunakan untuk menghapus beberapa item didalam listview
English please....
Please be so kind to translate this message in English so we can help you!
ChrisGT7
Using checkbox in Excel Macros for opening another file
Hi,
Can anyone help me in this. I have created a sheet for consolidation and when i run the macro i want to use checkbox to get data from other files(selected files) and get that data in the consolidation file. I am finding it difficult to use the checkbox for performing such action(to get data from other file which is not open)
Please somebody help me in this.
Thanks in advance
Change the background to a different color if check box is not
I am trying to figure out what code to use to change a check box background color to red if its not checked. And also, where do I input the code, in the form or report.
Thanks
CheckBox
Please Help
I want to publish all my worksheets in a excel workbook to one pdf file
but it publish only the lat sheet(sheet4) into pdf file.
Here's my code
Private Sub CommandButton1_Click()
If Check1.Value = True Then
Sheets("Sheet1").Select
If Check1.Value = True Then
Sheets("Sheet2").Select
If Check1.Value = True Then
Sheets("Sheet3").Select
If Check1.Value = True Then
Sheets("Sheet4").Select
ChDir "C:\Output"
ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:= _
"c:\output\New.pdf", Quality:=xlQualityStandard, _
IncludeDocProperties:=True, IgnorePrintAreas:=False, OpenAfterPublish:= _
True
End If
check box labeled as reverse
hi, will you please help me.. 1.I had 1 checkbox labeled as reverse..
2.a textbox for entry number.
3.labeled which will display the number...
And a cmd button ok... that where im going to put the code to display the entry number..
Will you please help me with the code,, please...
Checkbox selection
What should I do if I would like to have the selection of some checkboxes when the program starts from the previously job? I use VB6. Thanks.
Hi ! I'm trying an exercise
Hi ! I'm trying an exercise out there .
Its something like i'm only allow to tick two checked boxes and after that the rest of the boxes will auto disabled and when i unticked one
of them , all the boxes are enabled again . any ideas ?
10 checkboxes
I am going to use a control array of 10 checkboxes, Index from 0 to 9. The 2 first checkboxes (Index 0 and 1) will be your switches for the rest of the 8 checkboxes. Here is the code:
Private Sub Check1_Click(Index As Integer)
If Index < 2 Then
If Check1(0).Value And Check1(1).Value Then
For i = 2 To 9
Check1(i).Enabled = False
Next
ElseIf Not (Check1(0).Value And Check1(1).Value) Then
For i = 2 To 9
Check1(i).Enabled = True
Next
End If
End If
End Sub
When the 2 first checkboxes are both checked, then all the other 8 ones will be disabled. And if one of the 2 first checkboxed is unchecked, the 8 others will be enabled.
Checked and Unchecked, check boxes.
Hi!
I suggest that instead of using two check boxes try to use option button.
Requirements:
2 option buttons (optCheckAll, optUncheckAll).
10 check boxes (or as many as you want).
Option Explicit
Private Sub SetCheckBoxesValue(ByVal status As Integer)
Dim ctl As Control
For Each ctl In Me
If TypeOf ctl Is CheckBox Then ctl.Value = status
Next
End Sub
Private Sub optCheckAll_Click()
SetCheckBoxesValue 1
End Sub
Private Sub optUncheckAll_Click()
SetCheckBoxesValue 0
End Sub
Best regards,
tobz
help to solve this!!
i need to add the check box values into the fairpoint spread, and to display the highlighted row in respective fields...please do figure this out!!!
thanks in advance
checkboxes
how can i put value in checkbox1?
for example check box1=1 and i have 5 checkboxes and i want to add them. those check boxes with check will be add and the result will be on text 1
check1 = Card1
check2 = Card2
check3 = Card3
check4 = Card4
check5 = Card5
Value
check1 = 1
check2 = 2
check3 = 4
check4 = 8
check5 = 16
the answer will show in Text1
if check1 and check 2 is chosen:
Text1=3
pls reply as soon as possible :)
checkboxes
Here's the code
Private Sub CommandButton1_Click()
Dim c As Integer
If CheckBox1.Value = True Then
c = 1
Call Add(c)
CheckBox1.Value = False
End If
If CheckBox2.Value = True Then
c = 2
Call Add(c)
CheckBox2.Value = False
End If
If CheckBox3.Value = True Then
c = 4
Call Add(c)
CheckBox3.Value = False
End If
If CheckBox4.Value = True Then
c = 8
Call Add(c)
CheckBox4.Value = False
End If
If CheckBox5.Value = True Then
c = 16
Call Add(c)
CheckBox5.Value = False
End If
End Sub
Public Function Add(z)
z = Val(TextBox1.Text) + z
TextBox1.Text = z
End Function
I did this in Visual Studio 2008
Private Sub btnSum_Click(ByVal sender As System.Object, ByVal f As System.EventArgs) Handles btnSum.Click
Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim d As Integer
Dim e As Integer
Dim sum As Integer
If check1.Checked = True Then
a = 1
End If
If check2.Checked = True Then
b = 2
End If
If check3.Checked = True Then
c = 4
End If
If check4.Checked = True Then
d = 8
End If
If check5.Checked = True Then
e = 16
End If
sum = a + b + c + d + e
TextBox1.Text = sum
End Sub
checkboxes
how can i put value in checkbox1?
for example check box1=1 and i have 5 checkboxes and i want to add them. those check boxes with check will be add and the result will be on text 1
check1 = 1
check2 = 2
check3 = 4
check4 = 8
check5 = 16
the answer will show in Text1
if check1 and check 2 is chosen:
Text1=3
pls reply as soon as possible :)
vb 6
sir
I am using VB6 and MS Access 2007.
I want to display checkmark in datareport, from currant form .
Anybody can HELP me!!!!!
Unchecking the checkbox !
. i need a past reply . i only have limited time to finish it. ( AUGUST 30) only. :))
Unchecking the checkbox PArt II ! (VB8) please . :)
. im using inputbox by the way , when i check chkcheese... inputbox will show asking for how many quantity . when i enter 2 for example , it will mutiply to the value of my chkcheese which is 10 . and the answer will be 20 . so when i unchecked the chkcheese i want to erase its added value to the txtTamount . ??? help :))
. THANKS ALOT .
Unchecking the checkbox !
I need your help , i need the codes in check boxes , that when i unchecked the checkbox(chkcheese) which has the value of 10 for example. it will erase its value on the textbox1(txtTamount) and for an instance the txtTamount has already have 500 on it and only the (10) value of chkcheese will be remove because you unchecked it and 490 will be left in the txtTamount ?? a little complicated . ahe :)
. i will really appreciate those who r willing to heLp :)))) THANKS !!!
Unchecking the checkbox
Private Sub CheckBox1_Click()
Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim d As Integer
If CheckBox6.Value = True Then
b = 10
a = InputBox("Enter the number of items", "SAMS PIZZA STORE")
c = a * b
TextBox1.Text = Str(c)
End If
If CheckBox6.Value = False Then
d = d - c
TextBox1.Text = Str(d)
End If
End Sub
Saving a checkbox to access database
hey ya'll would someone help me with the code & properties for saving a check box to access database?
vb6 check box
dfwhow to check box data stored for ms access.
Checkbox db connect
I hope dis'll help
firstly, u cre8 a new table with a fieldname "check" then you set its type to "boolean" not "text", den you create ur vb form and add a checkbox, a dataset, connect the dataset to d table, and the checkbox to the fieldname, run the project den i hp u get what you want.
Ask for code
I am Doing Project On Petrol Pump Management System.
IF I Checked One Value And After Clicking On Add To Resource It Should add in Our List Box,Flex Grid Controls And Comboox
Checkbox Selection
Hi to all,
I need your help in check box control. My requirement is that Check1 is selected and at the same time there is validation if the validation is true then check1 = vbchecked else vbunchecked.
I did many times, it rotating the process as endless loop that is when i am assigning check1.value=0 then again it goes to the line private sub check1_click().
So please help me in this. Its very urgent.
Thanks,
Shailaja
Reset Checkbox
How can I reset the value of checkbox in this form?
use Check1.value = 0
use Check1.value = 0
Modifying stored details
I have a big problem concerning my checkboxes. I am a shop program and I have set my checkbox to store price and name details of a sandwich to 2 variables. I have a string that saves the name of the sandwich and a single to store the price. Here's the code for how i've done these
chkHamSalad_Click()
sngTotal = sngTotal + 1.5
strSelection = strSelection & " Ham Salad"
I want to know how I can remove the phrase " Ham Salad" from the string without removing the
entire contents of the string as I could have details for 100 other options also saved. Any help would be greatly appreciated thankyou.
Checkbox validation
Im doing a project..there i have about 11 check boxes. I want to restrict the user from clicking more than 3 checkboxes and if the user unchecks one checkbox he/she must be able to check another one instead and if he/she unchecks 2 he/she must be able to check 2 check boxes.... and so on....can you please help...its kinda urgent.....
Connecting a checkbox in database
Can you please tell me how to connect the value of the selected checkbox into an MS access table?Thank you
Limit number of checkbox checked
I have 10 check box and I only want five of them to be checked if they are going to check more than 5 a msg box will pop up.. plan to use it on a voting apps for the school senatorial election.
Limit number of checkbox checked
Private Sub chk_click(index As Integer) Dim i As Integer Dim c As Integer For i = 1 To 10 c = c + IIf(chk(i).Value = vbChecked, 1, 0) Next Select Case c Case Is < 5 For i = 1 To 10 chk(i).Enabled = True Next Case Else For i = 1 To 10 chk(i).Enabled = (chk(i).Value <> vbChecked) Next End Select End Subhow to view your checkbox to
how to view your checkbox to a another form
changing font styles...
how about if i want to have a menu that changes the font into bold? into italic? or even underline? can you help me... i need it As Soon As Possible...
conditional statements involving check boxes
Sir, what shuld I do in this case:
I am to make a restaurant's menu. It has the list of foods. one check box each meal. For example,
Name: chkSpaghetti
Caption: Spaghetti Php. 25.00
Name: chkBurger
Caption: Burger Php. 20.00
Name: chkDrinks
Caption: Drinks Php. 15.00
Name: cmdTotal
Name: txtTotal
that's the tools that I used, Sir.
What if I want the value of txtTotal.Text be the Value of the total of all checked orders? how and what commands should I use?
Thanks,
Yaire
(Hoping this comment will be read as soon as possible as well as answered) Thanks in advance Sir.
You will need to use if
dim iTotal as integer if chkSpaghetti.Value = 1 then iTotal = iTotal + 25 end if if chkBurger.Value = 1 then iTotal = iTotal + 20 end if ''' Do this for all of your check boxes ''' txtTotal.Text = iTotalYou might want to read the Beginners Guide on the left navigation bar it will walk you through a lot of these sort of things.VB check box
what if id like to see the items that the user choose in a message box?what i mean is that i like to see his hobbies in a message box?
Maybe this wil help Option
Maybe this wil help
Option Explicit
Private Sub Check1_Click()
If Check1 = vbChecked Then Check2.Enabled = False
If Check1 = vbUnchecked Then Check2.Enabled = True
If Check1 = vbChecked Then Check3.Enabled = False
If Check1 = vbUnchecked Then Check3.Enabled = True
End Sub
Private Sub Check2_Click()
If Check2 = vbChecked Then Check1.Enabled = False
If Check2 = vbUnchecked Then Check1.Enabled = True
If Check2 = vbChecked Then Check3.Enabled = False
If Check2 = vbUnchecked Then Check3.Enabled = True
End Sub
Private Sub Check3_Click()
If Check3 = vbChecked Then Check1.Enabled = False
If Check3 = vbUnchecked Then Check1.Enabled = True
If Check3 = vbChecked Then Check2.Enabled = False
If Check3 = vbUnchecked Then Check2.Enabled = True
End Sub
Private Sub Command1_Click()
Dim strInfo As String
If Check1 = vbChecked Then strInfo = "waarom"
If Check2 = vbChecked Then strInfo = "daarom"
If Check3 = vbChecked Then strInfo = "dus"
Label1 = strInfo
End Sub
Image Stretched Property
What is the code when I clicked a check box then the image in the image1 is stretched and when I click it again it is stretched again?
Image stretched property
What is the code when I clicked the stretched check box the image loaded in the image1 is stretched and when i clicked it again the image in image1 is stretched again.
check box
sir,
how can you pass the value of the checkboxe's control property in a program. Say to make the value of a check box be equal to 2....or grayed(disabled)
hey
what if i have 5 checkboxes.. when i select the first one, others will be disabled but selecting others excluding the first none will be disabled... what i'm asking is how to disable a checkbox???????
Solution
Think this is what you searching for.
Option Explicit
Private Sub Check1_Click()
If Check1 = vbChecked Then Check2.Enabled = False
If Check1 = vbUnchecked Then Check2.Enabled = True
If Check1 = vbChecked Then Check3.Enabled = False
If Check1 = vbUnchecked Then Check3.Enabled = True
End Sub
Private Sub Check2_Click()
If Check2 = vbChecked Then Check1.Enabled = False
If Check2 = vbUnchecked Then Check1.Enabled = True
If Check2 = vbChecked Then Check3.Enabled = False
If Check2 = vbUnchecked Then Check3.Enabled = True
End Sub
Private Sub Check3_Click()
If Check3 = vbChecked Then Check1.Enabled = False
If Check3 = vbUnchecked Then Check1.Enabled = True
If Check3 = vbChecked Then Check2.Enabled = False
If Check3 = vbUnchecked Then Check2.Enabled = True
End Sub
Private Sub Command1_Click()
Dim strInfo As String
If Check1 = vbChecked Then strInfo = "waarom"
If Check2 = vbChecked Then strInfo = "daarom"
If Check3 = vbChecked Then strInfo = "dus"
Label1 = strInfo
End Sub
Checkbox Control
What if I want to save the checkbox selections and save them for the next time the form loads?
soloution
if you want it disabled when thform loads:
Private Sub Form_Load()
Check5.Enabled = False
End Sub
If you want it disabled when you select check box 3:
Private Sub Check3_Click()
Check5.Enabled = False
End Sub
Hope that helps...
Post new comment