Showing posts with label design. Show all posts
Showing posts with label design. Show all posts

Saturday, 5 June 2021

How to Use Option Buttons (aka Radio Buttons or Option Groups)

 What are Option Buttons?

So what are Option Buttons, and what are they used for? Option Buttons are a user-friendly form control that enables users to select a single value from a group of given options.  This is done by clicking one of a number of boxes, with each box representing one of the available options.  When the user clicks a box to select the value, any previously selected boxes are unselected as a result.  In this way, only one value can be selected at any one time.  


Example of an Option Button Group.

For example, in the screenshot above, there are three options for the user to select one out of a possible three teams - team 1, team 2 and team 3.  The advantage of using an option button group over a combo box with the same available list of values is that it is quick and simple for the user to enter data.  It is also preferable to a textbox in so far as it limits the value entered to one in the group of options.  On the downside, an option button group tends to take up more space of the form, particularly if there are many options to choose from.  If this is the case, a combo box with data entry restricted to items in the list, maybe a better choice.

In the following exercise, we are going to re-create the Option Button Group from the above screenshot.  To begin with, let take a look at the underlying database table.

The underlying database table containing the "team" field 
for the Option Group's Control Source.

As we can see, the underlying table contains four fields - ID, firstName, surname and team.  It is the latter field, team, which is going to be the Control Source for our Option Button Group. Before we start the exercise it is worth mentioning that the Option Button Group is actually comprised of two separate types of control: first, we have the Option Group control, and then we have the individual Option Button controls which are contained within the Option Group.  So to re-create the Option Button Group in the exercise below, we will need to use 1 Option Group control, and 3 Option Buttons, four separate controls acting together as one.  It is the Option Group control that contains the Control Source property for the group as a whole, whilst the Option Buttons each have their own individual Option Value properties.

How to Create an Option Button Group

  1. Open the form in DESIGN VIEW.
  2. Select the OPTION GROUP control from the  DESIGN RIBBON
    and drag it down onto the form design grid.
  3. Whilst the OPTION GROUP control is still selected in the design grid, open or go to the PROPERTIES window, select the DATA tab, and then select team from the CONTROL SOURCE drop-down list (NB this assumes you have already set the CONTROL SOURCE of the form itself to the underlying table).
    Form design grid with the option group control 
    added (highlighted orange).  The property sheet is also visible
    for the control with team entered as the control source.

  4. Next, select the OPTION BUTTON control from the DESIGN RIBBON, and drag it down onto the OPTION GROUP which you added to the design grid in step 2.  You should notice the OPTION GROUP turn black once the OPTION BUTTON is over the control and ready to drop.  This indicates that the button will be added to the group.
  5. Whilst the OPTION BUTTON is still selected, open and/or go to the PROPERTY WINDOW, select the DATA TAB, and check the OPTION VALUE property.  It should say "1".  This is the value that will be bound to the team field if the button is selected by the user at runtime.
  6. Repeat steps 4 and 5 for the remaining two CONTROL BUTTONS checking the OPTION VALUE properties say "2" and "3" respectively.

    Design grid showing three option buttons added to the
    option group control.  The property sheet for the third control button
    (showing the option value property) is also visible.
The form should now be ready to open in FORM VIEW.  The screenshot below shows the finished form with the underlying table.  I have added some data to demonstrate how information contained in the Option Button Group is stored in the database.

Form with option button group.  Select an option button on the form results in the option value property being stored in the underlying database table.

Note how team 3 is selected for the Sarah Arden record (ID 7) in the option button group.  As you may remember, the option value property was set to "3" for the last button.  This is the value that has been stored in the underlying database table.

This post has shown how we create an option button group using a combination of an option group control and three option buttons.  I have demonstrated how the control source for the group as a whole is bound to a field in the forms underlying database table, and how each option button has a unique option value property which is the value stored if the user selects a given button at runtime.  

In a future post, I intend to show how option button groups can be used to control the behaviour of a form at runtime, rather than being bound to a field in an underlying database table. To do this I will demonstrate how we can reference the option button group with VISUAL BASIC code, and respond to its click events.

Friday, 4 January 2019

Changing "Entry Key Behaviour" to Allow New Lines within a Textbox

In my previous blog post, I wrote about Adding Rich Text Formatting to MS Access Data.  However, there was one related topic which I didn't cover - ie how to change the entry key behaviour to allow new lines within a text box.  This is done by changing the ENTRY KEY BEHAVIOR property of the text box in question.

The ENTRY KEY BEHAVIOR property set to 
NEW LINE IN FIELD for the txtDescription text box.
Let's imagine we have a text box on a form in which we are going enter a large amount of text data separated by paragraphs. We have set the field in the underlying table to accept LONG TEXT data, and perhaps also enabled rich text formatting.  The first thing we do is resize the text box in FORM DESIGN view by selecting the text box and dragging the lower right corner so it is large enough to display a good area of text without having to constantly scroll down.

If we left the ENTRY KEY BEHAVIOR property at its default setting, it would not be possible for a user to create a new paragraph within the text box whenever they hit the ENTER key.  What we need to do, therefore, is change the property value from DEFAULT to NEW LINE IN FIELD. This is how:

  1. Open the form in DESIGN VIEW.
  2. Select the text box control to be modified by clicking it.
  3. Open the PROPERTY SHEET by clicking the icon in the TOOLS group of the DESIGN ribbon (if it's not already open).
  4. Click the OTHER tab on the property sheet.
  5. Locate the ENTRY KEY BEHAVIOR property and change the value to NEW LINE IN FIELD.
Once the property has been changed, the user can enter text in the text box and use the ENTER key to create a new paragraph without the focus shifting to the next control in the tab order.

Above: Example of a text box with the ENTRY KEY BEHAVIOR property modified to
  NEW LINE IN FIELD.

Friday, 14 October 2011

Using The Tab Control for Tidy Form Presentation

The Tab Control is a type of form control used to aid presentation and enhance user-friendliness.  It works much the same way as the Access Ribbon - the user clicks a tab to reveal a new strip.  However, instead of Ribbon icons, these strips contain our text boxes or other form control that we choose.  As such, it allows us to separate the fields on our forms, displaying one group at a time. Here is a screen shot of one I prepared earlier:

Figure 1a: The Tab Control: Tab 1 "Personal".
Figure 1b: The Tab Control: Tab 2 "Address". 

Figure 1c: The Tab Control: Tab 3 "Education".

As you can see, the Employee Record Form in figure 1 above contains a Tab Control which is comprised of three separate Tabs.  The first tab shown in figure 1a has been given the caption, "Personal", and displays fields relating to the Employee's ID, Name and Date of Birth. The second tab in 1b relates to the employee's Address, and the third in 1c relates to Education.  As such, we see how the Tab Control has enabled us to organize the information into logical categories, in addition to presenting that information in a tidy and easy to access format.  In fact,we have condensed 11 fields to fit on a small Dialog form.

Lets take a look at how the form from figure 1 was created. 

Adding a Tab Control
  1. To begin with I created a new form by clicking the FORM DESIGN icon.  This is located in the FORMS group of the CREATE ribbon.
  2. I set the RECORD SOURCE property (via the DATA tab of the PROPERTY SHEET) to the appropriate table.
  3. I clicked the TAB CONTROL icon  (located in the CONTROLS group of the DESIGN ribbon), and clicked a position for it to go on the form design grid. A blank Tab Control with two pages appears on the grid.
    Figure 2: A blank Tab Control added to the
     Form Design Grid.
Customizing the Tab Control
The  process of customizing the Tab Control simply involved adding an extra tab page and giving each tab its own individual name - ie Personal, Address and Education.  
  1. I began by selecting the Tab Control by clicking its outer edge so that it was highlighted. 
  2. Then I clicked the INSERT PAGE icon  (located in the CONTROLS group of the DESIGN ribbon).  This added a new blank page to the tab control, thereby giving us the three required tabs.
  3. Next I clicked the part of the Tab Control which says PAGE1 to select this particular tab page. 
  4. I then changed the CAPTION property for PAGE1 to "'Personal".  This property is located on the FORMAT TAB of the PROPERTY SHEET.
  5. I repeated the process for the other two tab pages -  so I had a tabs for  "Personal", "Address" and "Education" respectively.
Adding Text boxes to the Tab Control
The final stage involved adding the text boxes to the tab control.  The key thing to remember here is that it is important to select the required tab page before adding the text box to the tab control.  It is also worth mentioning that if you are moving an existing form control to the tab control, you will need to cut and paste rather than simply drag and drop (otherwise it will sit on top of the tab control and not be a part of it).
  1. I began by clicking the ADD EXISTING FIELDS icon (located in the TOOLS group of the DESIGN RIBBON).  This opened the FIELD LIST pane.
  2. I then selected the Personal Tab of the tab control (like I did in stage three of the customization process above).  
  3. I then dragged the first four fields - EmployeeId, Firstname, Surname and DOB - from the pane over to the tab control and positioned them in the required location. When you try this yourself, notice how the tab control goes black as you position the text box. This shows that it is being added to the Tab Control rather than the form Detail.
  4. I repeated stages 2 and 3, adding the Address and Education related fields to the Address and Education tabs respectively.  
  5. All I had to do then was align and resize the text boxes for a professional finish.  A good way of doing this is to click on the text box and manually enter the grid position on the FORMAT tab of the PROPERTY SHEET - the TOP property determines the vertical grid position, the LEFT property the horizontal, and the WIDTH is self explanatory. You can also position the text box label's separately using the same method. 
Figure 3: Adding fields to the Personal Tab Page.

Tuesday, 10 November 2009

Creating an Access 2007 Form from Scratch

This post complements yesterdays article on Customizing an Access Form. This time we are going to look at Creating an Access 2007 Form from scratch.

1/ Begin by clicking the Form Design Icon on the Create Ribbon. This opens a blank new form in Design View.

Access Form Design Icon
The Form Design Icon on the far right of the Create Ribbon.


Access Form Design View
Form Design View and the Property Sheet.


2/ Before we start creating text boxes and other form controls, we are going to bind the form to an Access Table that has already been created. This is so Access knows where your forms' data is going to come from. We do this by setting the Record Source property. If the property window is not already open, click the property sheet icon in the Tools group of the Design Ribbon.

3/Select the Data Tab of the property sheet. This will display a grid of properties relating to your form's data. It is the Record Source property that we are currently interested in. Click the arrow to display a drop down list of potential database tables and queries that we can use. In this example we are going to use the table called tblAccounts, which we will select by clicking.

Record Source
Record Source property and the Property Sheet.


4/ We are now in a position to begin adding form Controls such as Text Boxes and Labels. These are located in the Controls group on the Design Ribbon. We shall now click on the text box icon and then move then cursor to the area of the form where we would like it to go. Then simply right click the mouse over this point. This will place the text box control on our form.

The Controls group of the Design Ribbon.
The Text Box control is on the far left of the image.


5/ We shall now set the Control Source property of the text box. This determines which field from the form's Record Source will be bound to the control. Do this by clicking the arrow to display a drop down list of field names from the table which we earlier selected as our record source. We shall choose the Description field. Like in stage 3, simply click the field name in the list to select.

The Control Source Property.
Selecting a field name from the drop down list.


6/ You can now give your control a meaningful name. This is now displayed anywhere on the form itself, but it will be the name that you use to reference it later on in the design process. Do this by clicking the Other tab of the property sheet. The Name property should be at the top of the grid. Access gives it a default name such as Text1. You can simply type the name Description over this on the grid.

The Name Property for our text box control.


7/ We shall now change the Caption property of the label on the left of the text box. Unlike the Name property which we set in the previous stage, the Caption is displayed on the form to provide information to the user. In this case, it is going to tell the user that the information to enter in the text box is going to be "Description". Do this be selecting the label on the design grid by right clicking so that it goes orange. Next click the Format Tab on the property sheet and type in "Description" on the property grid. Alternatively you can click the label on the design grid to select, and then click inside the label to overwrite the old label caption directly.

You can now repeat this stage, adding as many text box controls as you need.

Caption Property
The Caption Property for our Label control.


8/ We will now finish off the form by entering a title. Do this by clicking on the Label control on the Controls group of the Design Ribbon. Then choose a position at the top of the grid, and click to add the label control to our form. We can now add our title text the same way as we entered the caption in the previous stage. Once we have entered the title caption, we can now increase the font size and make the text bold. Do this by right clicking the label to select, and entering a new Font Size of 24, and clicking Bold in the Font group of the Home Ribbon. You will also need to resize the label by double clicking the the notch on the labels border.

Monday, 9 November 2009

Customizing an Access 2007 Form

Creating a form has always been easy with MS Access. There is the user friendly Form Design Wizard, and in Access 2007 you can also set up a basic form by clicking a single Icon. These methods are a great way to get started, and at a basic level they might even be all you need. However, at more advanced levels you will more than likely want to modify the design of your form manually, or even set up an Access Form from scratch. This post will explain how to modify an existing form.

1/ If you have do not have an existing form to work on, begin by creating a simple form using the Access Form Wizard or clicking the Form icon
on the Access 2007 Create Ribbon.

2/ When you open your form from the Navigation Window, it is ordinarily displayed in Form View. This is the view that you work in when you perform database tasks such as entering and updating records. We are going to be editing the form itself, and we do this by selecting Design View. Click the arrow under the Views Icon on the Home Ribbon. This gives you a selection of three views ie Form View, Layout View, and Design View. See screen below:



Select Design View from the drop down menu. A form in design view will look something like this:



The labels are the boxes on the left, and the text boxes, which will contain the actual data from the table, are located on the right. You are now in a position to customise the appearance of your form.

3/ To delete an unwanted text box, simply select it by clicking on once and pressing the delete key. If you select the right hand box the label will also delete automatically, but you can delete the label without also deleting the text box if you wish.

4/ You can adjust the length of a label or text box. Click the label or text box to select, and then hover the mouse on the edge of the box where there is a notch half way along the border.



At first all the text boxes may change size together as a group. To remove this grouping so that individual text boxes can be adjusted, click the small square with the cross in the centre (this appears top left of the group as you can see in the screen shot above); then click Remove from the Control Layout on the Arrange Ribbon - see below:



5/ You can move text boxes and labels to different areas on the form. Simply click and drag the box.

6/ You might need to increase the size of the form by clicking and dragging the edge of the design grid. To increase the size of the form vertically click the upper edge of the blue border and drag downwards. To increase the width of the form, click the right hand edge and drag to the right. You can also reduce the form size by dragging inwards.