Locked lesson.
About this lesson
Add a Yes/No checkbox control to a form.
Exercise files
Download this lesson’s related exercise files.
12.01 yes-no-date-type - Exercise.docx43.5 KB 12.01 yes-no-data-type - Exercise solution.docx
74.8 KB TechGurusTicketing28.accdb
1.5 MB TechGurusTicketing28 - Complete.accdb
1.5 MB
Quick reference
Data Types: Yes/No Checkbox
Add a Yes/No Checkbox to the form.
When to use
We add a Yes/No Checkbox to a form whenever we want to collect data that only has a Yes or No answer.
Instructions
Add the Yes/No Field to the table
Before we add a Yes/No checkbox to the form, we need to add it to the relevant table. In this example, we are going to use a Yes/No checkbox to establish if a customer is a VIP.
- Open ‘tblTicket’.
- Add a new field with the following properties:
- Name: VIP
- Data Type: Yes/No
- Description: Is this customer a VIP?
- Indexed: Yes (Duplicates OK)
- Switch to Datasheet View.
- Select three customers as VIPs.
Add the Yes/No Form Control
Now, we can add the Yes/No control to the form.
- Open ‘frmTicketMaintenance’.
- Switch to Design View.
- From the Form Design tab, in the Form Controls group, select Checkbox.
- Draw a text box on the form.
- Click the label and modify the properties in the Property Sheet:
- Name: VIPLabel
- Caption: VIP
- Click on the checkbox form control.
- From the Property Sheet, in the Control Source field, click the drop-down and select ‘VIP’.
- Switch to Form View and review the changes.
Hints & tips
- Find out more about data types in Help (F1).
- 00:04 Throughout this course so
- 00:05 far we've been using different data types when building our tables, but there
- 00:10 are still a couple of really important ones that we haven't used as yet.
- 00:14 So in this lesson, I just want to highlight those to you.
- 00:17 Now on the screen right now I've pulled up the help files for data types.
- 00:22 And as we look through this list of all of the different data types that we can add,
- 00:27 we've used many, many of these in our tables.
- 00:30 However, one of them that we haven't used yet is the Yes/No data type.
- 00:35 And you can see here that it says Yes or No values and
- 00:39 fields that contain only one of two values.
- 00:42 So, what does that mean in the context of the database that we're working on?
- 00:47 Well, if we take a look at the Ticket Maintenance form, maybe I want
- 00:53 to add a checkbox onto this form which tells me if this is a VIP customer or not.
- 01:00 And if the checkbox is ticked, then they are.
- 01:02 And if it's not ticked, then they're not.
- 01:05 That is where we would use the Yes/No data type.
- 01:09 So, the first thing we need to do here is we need to go back to tblTicket, and
- 01:13 let's jump into Design View.
- 01:16 And we need to add another field.
- 01:18 Now you could choose to add this a bit further up.
- 01:20 I'm just going to add it onto the end, and it's going to be called VIP.
- 01:24 Now this data type that we're going to use is Yes/No.
- 01:28 Let's add a description.
- 01:31 Is this customer a VIP?
- 01:33 Let's take a look at our field properties.
- 01:35 The format is Yes/No.
- 01:36 The default value is No, I could change that if I wanted to and have the default
- 01:42 value as Yes, but there are fewer VIPs than there are standard customers.
- 01:48 Is this going to be indexed?
- 01:49 Well, Yes, I might want to search for all VIP customers, and
- 01:53 duplicates are okay, because we could have multiple customers that are VIPs.
- 01:58 So, now that we've added that new field in, we need to go back and
- 02:02 make sure that we add this for our historical records.
- 02:05 So, if we switch back into Datasheet View,
- 02:09 let's save the table, notice now I have a new VIP column.
- 02:13 I'm going to go through and select which of these customers is a VIP.
- 02:18 So, we're going to say that Claire is, maybe this guy is,
- 02:23 and this person here, and then let's do one more.
- 02:27 So, four customers out of this list of VIP customers.
- 02:31 So, now that we have this field added in, I'm going to close down tblTicket, and
- 02:35 we're going to go back to our Ticket Maintenance form.
- 02:38 Because I want to have a checkbox on here which allows people to
- 02:43 specify if this customer is a VIP or not.
- 02:46 So, let's right-click and jump into Design View.
- 02:50 And I have a nice little convenient space at the top here just to add this checkbox.
- 02:55 Now we're going to use another form control to add this and
- 03:00 the one we want to add is this one just here checkbox.
- 03:04 So, let's draw a little checkbox like that,
- 03:09 and my checkbox also has a label.
- 03:13 Let's move this across very slightly.
- 03:16 And notice you can't really change the size of this checkbox.
- 03:19 It's kind of set by default.
- 03:22 Now I want to line up this with the ID and the TicketNumber.
- 03:25 So, let's select ID, TicketNumber, and Check 14.
- 03:29 Go to Arrange, Align, and do the Top.
- 03:34 And now I can move this checkbox down a little bit.
- 03:38 There we go, I think that will do.
- 03:40 Now I want to rename this label.
- 03:43 So, let's jump over to the Property Sheet, and
- 03:48 this is going to be VIP label, and the caption is just going to say VIP.
- 03:55 And once you've added that name,
- 03:57 again you might want to make a few further adjustments in there.
- 04:00 So, now if I take a look at this in Form View I have this little checkbox at
- 04:05 the top, and we can turn it off or we can turn it on.
- 04:09 So, now the final thing we need to do is we need to add
- 04:12 the control source to our checkbox.
- 04:14 So, let's select the checkbox and take a look at the Property Sheet.
- 04:18 Notice again it has no name, so let's call this VIP Checkbox,
- 04:24 and the control source is going to be that VIP field interval ticket.
- 04:32 So, I can click the drop down and let's select VIP.
- 04:35 So, now if we look at this informed view,
- 04:39 I should find that for Claire Smith VIP is ticked.
- 04:43 And as I go through my other records, as soon as I get to another VIP,
- 04:47 that checkbox is now ticked.
- 04:49 So, everything is working exactly as I'd like it to work.
Lesson notes are only available for subscribers.