Microsoft Access 2010 tutorial:Controls Part II


Controls Part II

V.5. Check Box

Check Box control is used to tick to choose a value or a group of values. It can be used alone or in an Option Group. To use a Check Box, you need to drag and drop it on a form. For example, when you tick a Female Check Box, it displays message that "You checked: Female". You can see the figure below:

 Access 2010 Check Box control

The example above shows how to use a Check Box control in an Option Group control.

To display the message like the figure above, follow the steps:

- Set the name of an option group control as OptGroup

- Click  OptGroup option group

- Press F4 if the Property Sheet is not displayed

- Click Event tab

- Click Microsoft Office Access 2007 Three Dot. In front of On Click event

- Type the VBA Code below:

Option Compare Database
__________________________________
Private Sub OptGroup_Click()
     If OptGroup.Value = 1 Then
         MsgBox "You checked: " & lblfemale.Caption
     End If
End Sub

V.6. Command Button

Command Button is used to trigger other tasks such as insert data, delete data, clear data, open form or report and so on. For example, when you click View Students Button, it displays all data into a List Box(lstStudent) by retrieving from TblStudent.

Microsoft Office Access 2007 Command Button

To display the data in the List Box as the figure above, follow the steps:

- Set the name and the caption of a Command Button control:

+ Name: CmdView

+ Caption: View Students

- Set the name of List Box:

+ Name: lstStudent

- Click View Students Command Button

- Press F4 if the Property Sheet is not displayed

- Click Event Tab

- Click Microsoft Office Access 2007 Three Dot. in front of On Click event

- Type the VBA Code below:

Microsoft Office Access 2007 Command Button Code



V.7. Option Button

Option Button is used to select a value. When you want to display a Yes/ No option on a form or report, use Option Button. You can choose only one option at one time. You use Option Buttons in Option Group also. Form example, when you click Single Option Button, it displays a message that "Your are single". And when you click Married Option Button, it displays a message that "You are married". You can see the figure below:

Access 2010 Option Button control

- Set the name and the caption of Option Button:

+ Name: OptSingle

+ Caption: Single

+ Name: OptMarried

+ Caption: Married

- Click Single Option Button

- Press F4 if the Property Sheet is not displayed

- Click Event Tab

- Click Microsoft Office Access 2007 Three Dot. in front of On Click event

- Type the VBA Code below:

Private Sub OptSingle_Click()
     OptMarried.Value = 0
     If OptSingle.Value = -1 Then
          MsgBox "You are single"
     End If
End Sub

For Married option button, follow the same step of practicing single option button. And type the VBA Code below:

Private Sub OptMarried_Click()
   OptSingle.Value = 0
    If OptMarried.Value = -1 Then
        MsgBox "You are married"
    End If
End Sub

V.8. Option Group

Option Group is used to group the controls such as check box, Option Button and other controls. Among  values of the controls that use in Option Group, there is only one value is allowed to select at a time. For example, when you click Single Option Button, it will display a message that "You selected: Single".

Access 2010 Option Group control

The example above uses Option Buttons in an Option Group. To do what you see on the figure, follow the steps below:

- Drag and drop an Option Group on a form

- Drag and drop two Option Buttons in Option Group

In order to make you easier to understand about Option Group, let me explain you a little bit about shape of Option Group.

Access 2010 Option group's shape

As you see on the frame shape figure above, we can say that Option Group is a combination of Label and Frame object. You see the word "Frame16" that is the caption of Frame. It is a Label control. We hope you understand Option Group clearly. Now, we continue our task:

- Set the name of option group and the caption of Label:

+ Name: OptMStatus

+ Caption: Marital Status

- Set the name and the caption of labels of option button:

+ Name: lblmale

+ Caption: Male

+ Name: lblfemale

+ Caption: Female

- Click OptMStatus

- Press F4 if the Property Sheet is not displayed

- Click Event tab

- Click Microsoft Office Access 2007 Three Dot. in front of On Click event

- Type the VBA Code b below:

Private Sub OptMStatus_Click()
    If OptMStatus.Value = 1 Then
        MsgBox "You selected: " & lblSingle.Caption
    Else
       MsgBox "You selected: " & lblMarried.Caption
    End If
End Sub

Comments




This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.