The Access Wizard Newsletter Tips Tricks and Traps for Access Users and Developers
August 2008

Option Groups 102 -- Binding to a Field

A few months back I got an Amazon Kindle -- it's a really nifty device. For those of you who haven't heard about the Kindle, it's an electronic book reader. Unlike reading text on a computer screen, the Kindle uses a different technology that is much easier on the eyes. When I first got the Kindle I thought it was exclusively for reading books; but it turns out that the Kindle is quite versatile. You can read magazines, newspapers and blogs; you can look up words in an onboard dictionary and you can do research on Wikipedia. Most amazingly you can ask the Kindle for information on virtually any subject via a service called Now Now and a human being will respond with a message back to the Kindle.

Last month I introduced you to the option group; like the Kindle it has more uses than meets the eye. This month we'll take a look at one of those uses - binding an option group to a field.

In this Issue
  • Tip of the Month- Double-Click On a Control to Bring Up Properties
  • Binding to a Field
  • Changing Stored Values
  • Conclusion and a Look Ahead

  • Binding to a Field

    We'll pick up where we left off last month with the option group I built to help manage departments of a summer camp.

    To refresh your memory or if if you'd like to review the details of how we got to this point see July 2008. Here's where we left off, with a list of choices presented to the user that allowed him or her to select one of the choices:

    The question now becomes "what can we do with something like this?" As with many Access controls, an option group can be bound (or associated with) a field in a table so that the user's choice will populate that particular field in the table. Let's go ahead and do that.

    As a first step, open your form in design view and then select the option group; you'll find that when you select the option group it will select all the objects within the option group as you can see below.

    Don't let this throw you-although all the objects in the option group have been selected, if you go to the properties view, you'll see that what you'll be acting on is the properties of the option group, not its individual components.

    If you click on the data tab as I have above, you'll see that one of the options you may change is the control source - the control source is the binding (hooking in) of a control on a form to a field in a table (or query). If your form is bound to a table or query you may choose to send the value selected in the option group to a field within the table or query through the binding process. It acts just as a text box or combo box does, but rather than what the user enters as text, it's the value of the item that is selected in the option box that is bound to the control

    This may be a tad counter-intuitive so let me explain. If you remember from last month when we built the option group, one of our decisions was what values we would assign to each of the options within our option group as in the picture below.

    So if the user has selected Land Sports the value that is stored is "1", Water Sports would be "2" and Arts & Crafts a "3." If you already have a pre-defined value for Land Sports of 256 for instance, then you could just as easily declare that value of Land Sports to be 256, either before or after having built the option group. In a like manner if you are storing the word "Land Sports" in your table you could substitute the value "Land Sports" in the value column. You're really not limited to what you use and the values declared, as long as the field in which you're going to store your values is defined to accept a value of that "type".

    You might remember that last month when I built this, I recommend using numbers as values because they are faster and easier to manipulate. For my purposes, when I design a table that will have many rows, I'll almost exclusively use numbers wherever practical and store the word equivalent in a separate lookup table. This is a very powerful technique that gives me great flexibility. I'll devote a future issue of the Wizard to the how and why of expanded use of lookup tables.

    Changing Stored Values

    It's a simple process to change the values that you originally chose for your option group selections. First, make sure you're in design view and click on the small circle that the user clicks on the select an option. You'll see a property box similar to the one below.

    In the property box above, I've selected the first option button (Land Sports) and clicked on the data tab; you can see that the option value is equal to one. If I wanted to store the word "Land Sports" rather than "1", I would simply type Land Sports in as the option value.

    Conclusion and a Look Ahead

    So far we've seen that it's easy to build an option group and bind the results to a field from the form.

    In a future issue we'll look at a situation where, rather than storing a value, we react to the user selection by changing something on the form.

    Tip of the Month- Double-Click On a Control to Bring Up Properties

    When you're designing a form, frequently you'll want to manipulate the properties of some object on the form. For instance in this month's wizard, we've been manipulating the properties of both the option group and actual option buttons.

    To get to an object's properties, you can alwb use the menu and choose "View Properties." However if you're a keyboard guy like me, an easy way to get to properties is to simply double-click on a control and that will bring up the properties view. This tip also works for reports.

    Quick Links...

    If you can't see all the Pictures Click Here for Online Version

    Custom Software Home

    Access Wizard Archives

    Our Services

    Join our mailing list!

    Forward email

    Safe Unsubscribe
    This email was sent to jim@custom-software.biz by jim@custom-software.biz.

    Custom Software | Copyright Custom Software All Rights Reserved | Westford | MA | 01886