Database Journal
MS SQL Oracle DB2 Access MySQL PostgreSQL Sybase PHP SQL Etc SQL Scripts & Samples Links Database Forum

» Database Journal Home
» Database Articles
» Database Tutorials
MS SQL
Oracle
DB2
MS Access
MySQL
» RESOURCES
Database Tools
SQL Scripts & Samples
Links
» Database Forum
» Sitemap
Free Newsletters:
DatabaseDaily  
News Via RSS Feed


follow us on Twitter
Database Journal |DBA Support |SQLCourse |SQLCourse2
 

Featured Database Articles

MS Access

Posted Jun 5, 2007

Designing Forms for Efficient and Accurate Data Entry - Page 4

By DatabaseJournal.com Staff

Entering Data with ActiveX Controls

The controls you see in the Design tab's Controls group will likely satisfy most of your form needs. However, you might have noticed that some controls that are commonly seen in Windows dialog boxes aren't available in the Controls group. For example, many Windows programs use spin buttons for entering numeric values, whereas others use a "calendar" control to enable users to choose dates via the mouse.

These and many other controls are available on your system as separate components that either come with the default Windows installation or are added to the system when you install Microsoft Office. (Other programs might also add their own controls to the system.) There are dozens of these so-called ActiveX controls, although only a few are suitable to be used on an Access form. The next three sections show you how to use three of them: a spin button, a scrollbar, and a calendar control.

Entering Numbers Using a Spin Button

A spin button comes with up and down arrows that the users can click to increment or decrement a value. Most spin buttons have a text box control beside them to show the current value. In most cases, the text box also gives users the choice of entering the number directly or selecting the number by using the spin button arrows. However, as you'll see, to use a spin button on an Access form, you can't make the text box editable, so the users must use the spin button arrows. Therefore, this control is useful only for fields that require relatively small numbers (to minimize the amount of clicking the users must do to get the required value).

Here are the steps required to add a spin button and companion text box to a form:

  1. In the Design tab's Controls group, click the Insert ActiveX Control button. Access displays the Insert ActiveX Control dialog box.

  2. In the Select an ActiveX Control list, click Microsoft Forms 2.0 SpinButton and then click OK.

  3. Adjust the dimensions of the control as needed. Note that if you make the control taller than it is wide, you get up and down arrows; if you make the control wider than it is tall, you get left and right arrows.

  4. In the Design tab's Controls group, click the Text Box button.

  5. Draw the text box on the form beside the spin button. Access adds the text box and an associated label. Make a note of the text box name because you need it later in these steps.

  6. Edit the text box label, as necessary.

  7. Click the spin button and choose Design, Property Sheet to display the control's property sheet.

  8. In the Data tab, use the Control Source property to specify the field in which you want the spin button value stored.

  9. In the Other tab, customize the spin button using the following properties:

    • Min—Sets the minimum value of the spin button.

    • Max—Sets the maximum value of the spin button.

    • SmallChange—Sets the amount that the spin button value changes when the users click one of the arrows.

  10. Ensure that the text box gets updated with the new spin button value whenever the users click an arrow. To do this, right-click the spin button, click Build Event, click Code Builder, and then click OK. Access opens the Visual Basic Editor and adds a stub for the Updated event, which you can delete. In the procedure list (the one on the right at the top of the module), click Change.

  11. Inside the Change procedure, type the following statement, where TextBox is the name of the text box you added in step 6 (see Figure 3.9):

    TextBox.SetFocus
  12. Figure 3.9
    Use a simple Visual Basic for Applications statement to keep the text box updated with the current spin button value.

  13. Choose File, Close and Return to Microsoft Office Access (or press Alt+Q or Alt+F11).

  14. Use the Property Sheet pane's drop-down list to choose the text box.

  15. In the Data tab, set the text box value equal to the spin button value by using the Control Source to add the following expression (where SpinButton is the name of the spin button control):

  16. =SpinButton
  17. Close the property sheet.

Figure 3.10 shows a form with a spin button and associated text box.

Figure 3.10
When you click the spin button arrows, the value displayed inside the text box changes accordingly.

Entering Numbers Using a Scrollbar

Scrollbars are normally used to navigate windows, but by themselves you can use them to enter values between a predefined maximum and minimum. In this context, they are very similar to spin buttons, so the procedure for adding them to your form is more or less the same:

  1. In the Design tab's Controls group, click the Insert ActiveX Control button. Access displays the Insert ActiveX Control dialog box.

  2. In the Select an ActiveX Control list, click Microsoft Forms 2.0 ScrollBar and then click OK.

  3. Adjust the dimensions of the control as needed. Note that if you make the control taller than it is wide, you get a vertical scrollbar; if you make the control wider than it is tall, you get a horizontal scrollbar.

  4. In the Design tab's Controls group, click the Text Box button, draw the text box on the form beside the scrollbar, and edit the label. Remember to make note of the text box name.

  5. Click the scrollbar and choose Design, Property Sheet to display the control's property sheet.

  6. In the Data tab, use the Control Source property to specify the field in which you want the scrollbar value stored.

  7. In the Other tab, customize the scrollbar using the following properties:

    • Min—Sets the minimum value of the scrollbar.

    • Max—Sets the maximum value of the scrollbar.

    • SmallChange—Sets the amount that the scrollbar value changes when the users click one of the scroll arrows.

    • LargeChange—Sets the amount that the scrollbar value changes when the users click between the scroll box and one of the scroll arrows.

  8. Right-click the scrollbar, click Build Event, click Code Builder, and then click OK. Access opens the Visual Basic Editor and adds a stub for the Updated event, which you can delete. In the procedure list (the one on the right at the top of the module), click Change.

  9. Inside the Change procedure, type the following statement, where TextBox is name of the text box you added in step 4:

  10. TextBox.SetFocus
  11. Choose File, Close and Return to Microsoft Office Access (or press Alt+Q or Alt+F11).

  12. Use the property sheet drop-down list to choose the text box.

  13. In the Data tab, set the text box value equal to the scrollbar value by using the Control Source property to add the following expression (where ScrollBar is the name of the scrollbar control):

  14. =ScrollBar
  15. Close the property sheet.

Figure 3.11 shows a form with a scrollbar and associated text box.

Figure 3.11
When you click the scrollbar arrows or drag the scroll box, the value displayed inside the text box changes accordingly.

Entering Dates Using a Calendar

Entering dates can be problematic because users might not use the proper format. For example, they might reverse the month and day, they might use an unrecognizable month abbreviation, they might leave out a date separator, and so on. To avoid these common data entry scenarios, you can add a calendar control to your form. The users enter a date by selecting the month and year and then just clicking the day of the month.

Follow these steps to add a calendar control to your form:

  1. In the Design tab's Controls group, click the Insert ActiveX Control button. Access displays the Insert ActiveX Control dialog box.

  2. In the Select an ActiveX Control list, click Calendar Control 12.0 and then click OK.

  3. Adjust the size and position of the control to ensure that the calendar is displayed properly.

  4. Click the calendar and choose Design, Property Sheet to display the control's property sheet.

  5. In the Data tab, use the Control Source property to specify the date field in which you want the calendar value stored.

  6. In the Other tab, use properties such as DayFontColor and GridCellEffect to format the calendar.

  7. Close the property sheet.

Figure 3.12 shows a form with a calendar control added.

Figure 3.12
With the calendar control, use the drop-down lists to select a month and year and then click the date you want.

Collecting Form Data via Email

Although small databases are often managed by a single person, larger databases require input from multiple people. If those people are on your network, such collaboration is most easily achieved either by placing the database in a shared network location or by moving some or all of the data to a SharePoint site. However, what do you do if your collaborators don't have network access? One solution would be to export the necessary tables and forms into another database and then email that database to the collaborators. When the data is returned, you could then import it back into your database.

Such a solution is workable, but a little too unwieldy to be practical. Fortunately, Access 2007 comes with a new feature called Access Data Collection (ADC) that makes email-based data collection much easier. With this feature, you create a form that includes fields for the data you want to collect, place that form in an HTML email message, and then send that message to every person from whom you want to collect the data. Each person fills in the form and returns the message, which is then saved in a special Outlook folder called Access Data Collection Replies. You then synchronize Access (by hand or automatically) with those replies, and the data is added to the underlying table.


Caution - Many people set up their email clients to read messages in plain text, and that's not good for ADC. First, viewing the ADC message in plain text prevents the user from seeing the form at all. Second, even if the user converts the message to HTML (by clicking the Information bar and then clicking Display as HTML), Access will perceive this as a "change" to the form, and it won't process the reply. That is, in the Access Data Collection Replies folder, the Data Collection Status column for the reply will say the following:

Failure: Cannot process this e-mail message. The form in this e-mail message is either corrupt or has been modified.

The user must turn off the Outlook option to read messages in plain text (choose Tools, Trust Center, click E-mail Security, and then click to deactivate the Read All Standard Mail in Plain Text check box), reply to and fill in the ADC form, and then reset the plain text option.


Sending the Access Data Collection Email Message

Unlike the other forms you've seen in this chapter, an ADC form cannot be created by hand. Instead, Access runs a wizard that builds the form step by step, as shown in the following procedure:

  1. Use the Navigation pane to click the table you want to use to store the collected data.

  2. Choose External Data, Create E-mail. Access starts the ADC Wizard.

  3. In the initial wizard dialog box, click Next. The wizard asks whether you want to use an HTML form or an InfoPath form.

  4. Click HTML Form and then click Next.

  5. If the table already contains data, the wizard asks whether you want to collect new information or update existing information. Click one of the following options and then click Next:

    • Collect New Information Only—Click this option to send a blank form for new data.

    • Update Existing Information—Click this option to send existing data for the recipient to edit. The record that contains the recipient's address is the record the recipient will edit.

  6. For each field you want to include in the form, click the field and then click > (or click >> to add all the fields). Click Next.

  7. If you want Access to synchronize with Outlook automatically when the replies arrive, click to activate the Automatically Process Replies and Add Data to Table check box (where Table is the name of the table you chose in step 1) and then click Next.

  8. Choose how you want to specify the message recipients (click Next after you've made your choice):

    • Enter the E-mail Addresses in Microsoft Office Outlook—Click this option to enter the recipients by hand in the Outlook message window that appears later. Skip to step 10.

    • Use the E-mail Addresses Stored in a Field in the Database—Click this option if you have the recipients' addresses stored in the current database. Proceed to step 9.

  9. Specify the addresses in the database using one of the following options (click Next when you are done):

    • The Current Table or Query—Click this option if the email addresses are stored in the table you're using with ADC. Use the associated list to click the field that contains the addresses.

    • An Associated Table—Click this option if the addresses reside in another table that's related to the current table. First, use the associated list to click the field in the current table upon which the relationship is based. Second, when Access displays a list of fields in the related table, use the list to click the field that contains the email addresses.

  10. Edit the message Subject and Introduction, as needed. If the addresses came from the Access database, click where you want the addresses added: the To Field, Cc Field, or Bcc Field. Click Next.

  11. You now have two ways to proceed:

    • If you choose an Access field for the recipient addresses, click Next. Access displays a list of the recipients with check boxes for each address. Leave the check boxes activated for the recipients you want to receive the message. When you are done, click Send.

    • If you will be specifying recipients via Outlook, click Create to create the message, select the recipients, and then click Send.

Replying to an Access Data Collection Email Message

If you receive an ADC message, you need to fill in the fields and return the message. Here are the steps to follow:

  1. Click the Access Data Collection message and then click Reply. Access displays the message window.

  2. Scroll down the message body until you see the form, as shown in Figure 3.13.

  3. Figure 3.13
    When you reply to an ADC message, fill in each form field in the body of the reply.

  4. Click inside a form field and type the data.

  5. Repeat step 3 for each field.

  6. After you've filled in each field, click Send.

Managing the Access Data Collection Replies

As I mentioned earlier, when you receive replies to your messages, they are automatically routed to the Access Data Collection Replies folder in Outlook. (This is a subfolder of the Inbox folder.) If you didn't set up Access to handle the replies automatically, follow these steps to handle a reply manually:

  1. In Outlook, open the reply.

  2. Click Export to Access. Outlook asks you to confirm.

  3. Click OK. Outlook exports the data.

  4. Click OK.

From Here

→ To learn how to work with the Label control, see "Adding Labels to the Form." (Chapter 2)

→ To learn how to work with the Text Box control, see "Adding Text Boxes to the Form." (Chapter 2)

→ For the specifics of the Expression Builder, see "Working with the Expression Builder." (Chapter 11)

→ To learn about inner joins, see "Establishing Table Relationships." (Chapter 12)

→ For the details on building SQL SELECT statements, see "Using SQL to Perform a Select Query." (Chapter 15)


© Copyright Pearson Education. All rights reserved.

Microsoft® Office Access 2007 Forms, Reports, and Queries
Paul McFedries
May 2007, Paperback, 408 pages
ISBN10: 0789736691
Publisher: Pearson Education
Buy this book


MS Access Archives

Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 




Latest Forum Threads
MS Access Forum
Topic By Replies Updated
Help With Microsoft Access kasy 0 September 4th, 07:35 PM
Linked table not sorting or filtering - ODBC error Java 1 August 28th, 10:37 AM
Use Parameter in select statement (Sql in Microsoft Access) katty.jonh 1 July 25th, 06:45 AM
Query Issue algebroni 7 July 23rd, 04:22 PM