Locked lesson.
About this lesson
Add option buttons to the form.
Exercise files
Download this lesson’s related exercise files.
13.01 form-controls-option-buttons - Exercise.docx43.3 KB 13.01 form-controls-option-buttons - Exercise solution.docx
85.4 KB TechGurusTicketing30.accdb
1.6 MB TechGurusTicketing30 - Complete.accdb
1.6 MB
Quick reference
Form Controls: Option Buttons
Add Option buttons to the form.
When to use
We add option buttons to a form whenever we want to specify the ticket as being part of a category or group.
Instructions
In this example, we need to add an option group containing three option buttons to categorize this ticket as hardware, software, or other.
Option Group
An option group contains the different option buttons. We can add option buttons using the form wizard. Access numbers the different options. For example, hardware=1, software=2, other=3. We use the numeric values of each option to categorize the tickets.
Adding the Category Field
First, we need to add the category field to 'tblTicket'.
- Open ‘tblTicket’.
- Add a new field with the following properties:
- Name: Category
- Data Type: Short Text
- Description: Category for this ticket
- Field Size: 30
- Required: Yes
- Allow zero Length: No
- Indexed: Yes (Duplicates OK)
- Switch to Datasheet View.
- In the ‘Category’ field, add a number 1, 2, or 3 to every record in the table.
Add Options Buttons
Now we need to add the form control to 'frmTicketMaintenance'.
- Add Option Buttons to ‘frmTicketMaintenance’ with the following properties
- Option 1 - Hardware
- Option 2 - Software
- Option 3 - Other
- From the Form Design tab, in the Form Controls group, select the Option Group form control.
- Draw the control on the form.
- Step through the Option Group Wizard.
- Type the labels ‘Hardware’, ‘Software’, and ‘Other’.
- Click Next.
- Choose ‘Hardware’ as the default value.
- Accept all defaults.
- Add the caption ‘Category’.
- Click Finish.
- Arrange the fields on the form.
- Click on the form control group.
- From the Property Sheet, in the Control Source drop-down, select ‘Category’.
- Switch to Form View and check the buttons are working.
- 00:04 In this section of the course, we're going take a deeper dive into forms.
- 00:09 And we're going to look at form controls, form themes, and also form navigation.
- 00:16 So, let's start out in this lesson by taking a look at some of the other form
- 00:20 controls that we haven't explored yet.
- 00:22 Now, I'm currently viewing the ticket maintenance form.
- 00:25 And it might be that I want to have some option buttons on here,
- 00:30 which allow me to specify if this call is related to hardware,
- 00:35 software or something else.
- 00:37 And for this we can use the option control.
- 00:40 So let's jump into design view and take a look at our controls up here.
- 00:45 Now when you want to add different options,
- 00:48 you need to add an option group first and then add the different options.
- 00:52 And the way that this works is that, for example, if I want to have
- 00:57 my first option as hardware that is going to equal option one.
- 01:01 Software is going to be option two and other is going to be option three.
- 01:07 So that is kind of how you need to think about this when you're creating option
- 01:11 buttons.
- 01:12 So the first thing I need to do, as always,
- 01:15 is we need to add another field into TBL ticket.
- 01:18 So let's close down ticket maintenance and click on yes and reopen TBL ticket.
- 01:24 Now we're going to jump into design view.
- 01:26 And we're going to add another field at the bottom here, and
- 01:30 I'm going to call mine category.
- 01:32 Now it's going to be hardware, software or other so
- 01:35 short text is going to be the correct data type.
- 01:38 And we're going to say category for this ticket.
- 01:43 Let's check our field properties.
- 01:46 Field size, let's take this down to 30.
- 01:50 Is it required?
- 01:51 Well yes, it is.
- 01:52 Are we going to allow zero length?
- 01:53 No, we're not.
- 01:55 Is it going to be indexed?
- 01:56 Well yes, I may want to search on the category.
- 02:00 So now if we jump into datasheet view and save the table,
- 02:04 we now have a new category at the end.
- 02:07 So I'm going to go through and assign a category to each of these tickets.
- 02:12 So now I have a category assigned to each of my tickets.
- 02:15 Now we need to add an area on the ticket maintenance form where we can specify
- 02:20 which category the ticket falls under.
- 02:22 So, let's close down to TBL ticket and reopen ticket maintenance.
- 02:29 We're going to jump into design view and
- 02:32 I'm going to add these option buttons in this space just here.
- 02:36 So the first thing we need to do here is add an option group to house
- 02:41 our option buttons.
- 02:43 And this is the control that we want just here option, group.
- 02:47 So let's drag this across.
- 02:51 And now I can define my label names.
- 02:54 So we want hardware,
- 03:00 Software, And other.
- 03:05 And click on next.
- 03:07 And at this point I can set which option I want to use as the default.
- 03:11 So I'm going to go with hardware.
- 03:13 Let's click on next.
- 03:14 And you can see here the values that it's assigned to each one.
- 03:18 So one, two and three.
- 03:19 And now I can choose where I want to store these values, so
- 03:23 I'm going to select the category field and click on Next.
- 03:27 I can then specify what type of controls I want to use in the option group.
- 03:32 Now I want to use option buttons and then I can use a style.
- 03:37 So I have a etched, flat, raised, shadowed, or sunken.
- 03:44 Now, I think I'm just going to go with etched and click on next.
- 03:49 Now I can choose a caption for my option group.
- 03:52 So I'm going to call this category and click on finish.
- 03:58 And now take a look at what I've got.
- 04:00 Now it's also worth noting that I've used the little wizard to walk through and
- 04:04 add those option buttons.
- 04:05 You could cancel on that wizard and
- 04:07 add the option buttons yourself by choosing the option Button Control.
- 04:12 So now I can move these into place.
- 04:15 So we want hardware first, then we want software.
- 04:18 And then we want other over here.
- 04:22 So, let's take a look at this in form view.
- 04:26 Well, take a look at that.
- 04:28 Now it still looks a little bit messy.
- 04:31 I'm probably going to want to reject the design around a bit and
- 04:34 just make this not quite as wide.
- 04:36 And there we go.
- 04:37 With a bit of reorganization that looks a lot better.
- 04:41 So if we jump back into design view, and select our option group,
- 04:46 we can go through and start renaming our labels.
- 04:50 Now I think you know how to do that.
- 04:51 So just to save a bit of time,
- 04:53 we're simply going to rename the one that we have selected.
- 04:56 So this is called category and
- 05:01 the label name is category
- 05:08 Label and I'm happy with the caption as category.
- 05:12 Now if we select the group again, we can see that the control source is
- 05:15 category because that's what we set up when we were going through that wizard.
- 05:20 Now if we jump into a form view, does this appear to be working?
- 05:25 Well, no because I know that I assigned the category of hardware to
- 05:30 Claire Smith in TBL ticket.
- 05:32 So why isn't this working?
- 05:35 Well, it's because when I added hardware, software and
- 05:39 other into TBL ticket, I should have been adding it's numeric equivalent.
- 05:44 So instead of hardware, a number one, instead of software,
- 05:47 a number two, instead of other, a number three.
- 05:50 So we need to go back to TBL ticket and replace these values.
- 05:55 So I'm going to go through and do that now.
- 05:57 So, there we go.
- 05:59 Let's close down table ticket and now take a look at the record.
- 06:03 Hardware is selected.
- 06:05 And if I scroll to the next record,
- 06:08 I should find that all of these have updated correctly.
- 06:12 So something to watch out for there.
- 06:14 Remember it has to be the numeric value as opposed to actually typing in
- 06:19 the category name.
Lesson notes are only available for subscribers.