Anda di halaman 1dari 14

Search

Visual Basic 6 (VB6)


Home Tutorials

RSS: Site Feed

VB Code

Tutorials

Database

Sub Box

Understanding Check Boxes

Twitter: Visual Basic


Facebook: Visual Basic

Level:

Access Visual Basic Code


VB6 to VB Net
Download Visual Basic 6

Navigate To

Mathcad Prime 2.0, Nyhet


www.alfasoft.com
En berkningsingenjrs sjlvklara verktyg! Prova gratis i 30 dagar
Written By TheVBProgramer.

Home

The checkbox acts as a "toggle" control: if it's on, clicking it turns it off; if it's off,

Tutorials

clicking it turns it on. Unlike the option button, the operation of each checkbox on

Source Code Samples

a form or frame is independent of all other checkboxes; changing the status of one

VB.NET Tutorials

does not affect other checkboxes.

Add Your Tutorial


Forums

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

Articles

is of the Integer type. A value of 0 means "off", a value of 1 means "on". You can

External Links

use the VB constants vbUnchecked or vbChecked for 0 or 1, respectively.

Advertise Here!

Following is a checkbox demo. The form contains 6 checkboxes within a frame,

Contact Us

named chkHobby1, chkHobby2, chkHobby6. The form also contains a


command button called cmdOK and a label called lblInfo. This is the form at

Guides

design time:

Beginner Guide
Controls Guide
Understanding forms
Timer control
Multiple Forms
Everything Images
Control arrays
Option Buttons
Check Boxes
Math Game
(o) Hangman
(o) Tic Tac Toe
(o) Calculator
(o) Cryptogram
(o) Concentration
Database Guide

The code behind the OK button is:


Private Sub cmdOK_Click()

User login
Username: *

Dim strInfo As String


strInfo = "Items selected:"
If chkHobby1 = vbChecked Then strInfo = strInfo

Password: *

& " aerobics"


If chkHobby2 = vbChecked Then strInfo = strInfo
& " reading"

Log in
Create new account
Request new password

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.

Similar links
Database Access with the Data Control
Using ADO and the ListView control
Visual Basic Power Pack
SQL Databases Create, Update, and Query
VB6 Animated Charts (With FusionCharts)
VB6 Downloads
Common Dialogs Allow A professional VB app
Using Toolbars in Visual Basic Tutorial
Working with Menus in VB6
Creating your own Drag and Drop apps in VB6

If you enjoyed this post, subscribe for updates (it's free)


Email Address...

Checkbox code using ADODC


Connection

Subscribe

Tue, 02/14/2012 - 19:22 iamloved (not verified)

Hi, what is the code for checkbox connected in a database (ADODC CONNECTION)
Thanks
reply

hi,do you means when


checkbox

Tue, 03/20/2012 - 23:37 sarahYong (not verified)

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
reply

menggunakan Check Box pada


listview di VB 6.0

Wed, 08/31/2011 - 07:14 Ruly (not verified)

Bagaimana source code untuk menggunakan check box dalam listview pada VB 6.0,
yang akan digunakan untuk menghapus beberapa item didalam listview
reply

English please....

Fri, 09/02/2011 - 11:46 ChrisGT7

Please be so kind to translate this message in English so we can help you!


ChrisGT7
reply

Using checkbox in Excel


Macros for opening another file

Thu, 05/12/2011 - 04:41 Pavan (not verified)

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
reply

Change the background to a


different color if check box is not

Fri, 05/06/2011 - 09:07 Gina (not verified)

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
reply

CheckBox

Thu, 03/31/2011 - 01:26 peter.cloete

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
reply

check box labeled as reverse

Sun, 03/06/2011 - 23:20 none (not verified)

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...
reply

Checkbox selection

Wed, 02/23/2011 - 03:39 EgyipTomi (not verified)

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.
reply

Hi ! I'm trying an exercise

Tue, 01/18/2011 - 04:32 Anonymous (not verified)

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 ?
reply

10 checkboxes

Fri, 02/25/2011 - 12:34 ChrisGT7

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.
reply

Checked and Unchecked, check


boxes.

Thu, 01/20/2011 - 04:54 tobee

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
reply

help to solve this!!

Thu, 11/25/2010 - 21:47 vignesh (not verified)

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
reply

checkboxes

Thu, 09/16/2010 - 08:59 Anonymous (not verified)

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 :)
reply

checkboxes

Wed, 12/08/2010 - 13:16 Anonymous (not verified)

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
reply

I did this in Visual Studio


2008

Fri, 10/01/2010 - 04:08 Preeti W (not verified)

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
reply

checkboxes

Thu, 09/16/2010 - 08:31 Anonymous (not verified)

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 :)
reply

vb 6

Wed, 09/15/2010 - 07:24 hijaz (not verified)

sir
I am using VB6 and MS Access 2007.
I want to display checkmark in datareport, from currant form .
Anybody can HELP me!!!!!
reply

Unchecking the checkbox !

Tue, 08/17/2010 - 05:38 Anonymous (not verified)

. i need a past reply . i only have limited time to finish it. ( AUGUST 30) only. :))
reply

Unchecking the checkbox


PArt II ! (VB8) please . :)

Tue, 08/17/2010 - 05:35 Anonymous (not verified)

. 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 .
reply

Unchecking the checkbox !

Tue, 08/17/2010 - 05:23 Anonymous (not verified)

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 !!!
reply

Unchecking the
checkbox

Thu, 12/09/2010 - 12:15 Anonymous (not verified)

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
reply

Saving a checkbox to access


database

Mon, 02/15/2010 - 00:19 russ (not verified)

hey ya'll would someone help me with the code & properties for saving a check box to
access database?
reply

vb6 check box

Mon, 12/14/2009 - 08:23 oza dinesh (not verified)

dfwhow to check box data stored for ms access.


reply

Checkbox db connect

Wed, 12/21/2011 - 15:29 Leksman (not verified)

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.
reply

Ask for code

Sat, 08/08/2009 - 12:22 yogi (not verified)

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
reply

Checkbox Selection

Thu, 04/09/2009 - 00:14 Shailaja (not verified)

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
reply

Reset Checkbox

Sat, 02/28/2009 - 21:20 arafat21

How can I reset the value of checkbox in this form?


reply

use Check1.value = 0

Tue, 06/08/2010 - 00:32 Anonymous (not verified)

use Check1.value = 0
reply

Modifying stored details

Mon, 02/23/2009 - 06:11 lawrenceangel

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.
reply

Checkbox validation

Sun, 02/22/2009 - 07:04 Hasitha (not verified)

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.....
reply

Connecting a checkbox in
database

Fri, 01/30/2009 - 17:33 Em (not verified)

Can you please tell me how to connect the value of the selected checkbox into an MS
access table?Thank you
reply

Limit number of checkbox


checked

Wed, 01/21/2009 - 19:58 Linmer (not verified)

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.
reply

Limit number of checkbox


checked

Wed, 03/04/2009 - 14:26 dvwright (not verified)

Private
Dim
Dim
For

Sub chk_click(index As Integer)


i As Integer
c As Integer
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 Sub
reply

how to view your checkbox to

Wed, 11/26/2008 - 09:55 jenking (not verified)

how to view your checkbox to a another form


reply

changing font styles...

Sat, 09/27/2008 - 22:14 darel (not verified)

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...
reply

conditional statements involving


check boxes

Wed, 09/03/2008 - 03:57 Yaire (not verified)

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.
reply

You will need to use if

Wed, 09/03/2008 - 09:31 Admin

You will need to use if statments. For example in your cmdTotal click event you will
want to add this code:
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 = iTotal
You might want to read the Beginners Guide on the left navigation bar it will walk
you through a lot of these sort of things.
reply

VB check box

Fri, 07/25/2008 - 02:47 chei (not verified)

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?
reply

Maybe this wil help Option

Fri, 06/20/2008 - 13:21 Anonymous (not verified)

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
reply

Image Stretched Property

Sat, 08/04/2007 - 01:29 Tabshrine

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?
reply

Image stretched property

Sat, 08/04/2007 - 00:53 Anonymous

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.
reply

check box

Sat, 07/28/2007 - 23:43 Anonymous

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)
reply

hey

Tue, 05/08/2007 - 18:35 Anonymous

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???????
reply

Solution

Sat, 06/21/2008 - 04:51 Anonymous (not verified)

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
reply

Checkbox Control

Wed, 07/18/2007 - 08:55 Anonymous

What if I want to save the checkbox selections and save them for the next time the
form loads?
reply

soloution

Sun, 05/27/2007 - 15:01 Anonymous

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...
reply

Post new comment


Your name:
Anonymous
E-mail:
The content of this field is kept private and will not be shown publicly.

Homepage:

Subject:

Comment: *

Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
Lines and paragraphs break automatically.
You can enable syntax highlighting of source code with the following tags: <code>,
<blockcode>. The supported tag styles are: <foo>, [foo].

More information about formatting options


Word verification: *

(verify using audio)


Type the characters you see in the picture above; if you can't read them, submit the form and a new
image will be generated. Not case sensitive.

Preview

Microsoft Pinpoint
pinpoint.microsoft.com

Hitta Teknikexperter, Programvaror och IT tjnster hr!


Unless otherwise noted, all content on this site and in the source samples is Copyrighted
2011 by the owner of vb6.us. All rights reserved - Contact Information

Anda mungkin juga menyukai