Educate Users About Your Application with Startup Tips
This article may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist. To maintain the flow of the article, we've left these URLs in the text, but disabled the links.
Educate Users About Your Application with Startup Tips
This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.by Sean Kavanagh
When you provide instructions for using an Access application you've created, you probably organize the documentation so that users can get up to speed as quickly as possible. To do so, you likely start with just enough information so users can perform essential tasks. Then, once they've mastered the basics, they can learn additional features and techniques that may be more efficient, but would be confusing without a solid foundation.
Unfortunately, this "walk before you run" approach has a problem--many users will never return to their documentation to learn about additional features. One way that you can ensure that users are aware of your application's features is to display startup tips when the application is launched, such as the example shown in Figure A. In this article, we'll show you how to implement such a tip feature. We'll also show you how to provide users with control over whether the tips are displayed at startup and what types of tips are displayed.
Figure A: You can help users get the most out of your application by providing tips at startup.
By this point, users have grown accustomed to features like Office's Tip Of The Day. By replicating this functionality, you can communicate brief tips and techniques in a manner that users are comfortable with. We'll use a hidden table in a database to store tips that are displayed in a form at startup. As you've probably noticed with applications that provide startup tips, the "Tip of the Day" phrase is somewhat inaccurate. The tips have nothing to do with a particular day, they're simply rotated each time you open the application so that you don't see the same tip each time. To ensure that a different tip is displayed each time someone opens your Access database, we'll store the ID of the tip that's displayed when the user closes the tip form. Then, the next time the form is opened, we'll use code to display the next tip in the underlying table.
To store the tip ID information, we'll use techniques we discussed in last month's article "Maintain custom settings using the Windows registry." We'll build upon the previous techniques to show ways to manage custom application options. For instance, you also want to accommodate power users who may not have any interest in seeing tips every time they open the database. We'll use registry keys to give users control over how and what tips are displayed.
Set up the data and form
Before we get into creating code, let's set up the basic data and form we'll work with. We'll store the text for the tips in an Access table. In a new Access database, use Table A as a guide for creating a table called tblTips with TipID as its primary key. Then enter the sample data shown in Figure B.
Table A: Specifications for tblTips
Figure B: This table will be the record source for your Tip Of The Day form.
Create the Tip Of The Day form
Now, let's set up the form that displays your tips. Close tblTips and make sure it's selected in the Database window. Then, choose Form from the New Object button's menu and click OK in the New Form dialog box. Using Figure C as a guide, add and orient the three fields from tblTips. Then, ensure that the Control Wizards button isn't selected on the Toolbox and add the checkbox and command button controls shown on the bottom of the form. Finally, use Table B to set the controls' properties and save the form as frmTipOfTheDay.
Figure C: This basic form is designed to display different tips when users launch the application.
Table B: frmTipOfTheDay object properties
|Tip Of The Day
|Checkbox Label||Caption||Don't show any tips at startup|
Save tip information to the registry
Let's attach some code to the form's cmdClose button to save information to the registry. First, click the Code button on the Form Design toolbar. Then, choose cmdClose from the Object dropdown list. At the insertion point, enter the code shown in Listing A.
Listing A: Code to save settings to the registry
If Me.chkTips = -1 Then SaveSetting "MyApplication", _ "TipSettings", "ShowTips", 0 End If SaveSetting "MyApplication", _ "TipSettings", "LastTip", Me.TipID DoCmd.Close
To save information to the registry, we use the
SaveSetting statement. As you can see, we created two registry keys,
LastTip. We arbitrarily chose the imaginative name MyApplication for our application and we're storing all of our registry keys in a section named TipSettings.
If the chkTips box is selected on the form, it will have a value of -1, indicating that the user doesn't want tips shown the next time that the application is launched. Therefore, we stored the value that's equivalent to
False, 0, in the
ShowTips registry key. Regardless of what the user's tip preference is, we store the TipID of the current tip in the
LastTip key. If the two keys don't already exist in the registry, the
SaveSetting statement creates them. If the keys already exist, they will be updated without raising an error.
Retrieve the ShowTips key
Now, we'll use the
GetSetting function to retrieve the
ShowTips value from the registry and determine whether frmTipOfTheDay should be opened. First, choose Form from the Object dropdown list. Ensure that Load is selected from the Procedure dropdown list and then enter the code shown in Listing B at the insertion point.
Listing B: Code to retrieve the
If GetSetting("MyApplication", _ "TipSettings", "ShowTips") = "0" Then DoCmd.Close acForm, "frmTipOfTheDay" Exit Sub End If
Note that when we initially saved the
ShowTips key's value, we simply saved it as 0. However, when we check the value using
GetSetting, we enclose the value in double quotes. This is because
GetSetting returns the value as a string, regardless of the data type you initially saved. If the value in
ShowTips equals 0, our code immediately closes the tip form and exits the procedure.
Test the existing procedures
At this point, you may want to check out the functionality of our two procedures. Save and close the module, then save the form and close it. You can open and close the form as many times as you want without incident. Now, open the form, select the Don't Show Any Tips At Startup check box, and click Close. When you try to open the form again, you can't.
Taking control of your application with default settings
If you save user preferences to the registry, you'll most likely want to provide an easy tool for setting the preferences, such as a dedicated form. Let's create such a form and in the process examine how you can use the
default argument in the
GetSetting function to handle cases where a setting hasn't been explicitly specified.
Our control panel form will allow users to determine whether tips are shown at startup. In our application, we included humorous tips, like the "You can hurt yourself if you run with scissors," tip you may have seen when launching Access. We'll also give users a way to filter out these tips so that they only see those that have a genuine impact on the application.
Since these values may not be explicitly set when a user launches the application, we'll assume that both settings should be true by default. In addition, we'll provide users with the ability to reset the tip settings by deleting all of the associated registry keys.
Set up the control panel form
First, click the New button on the Forms sheet of the Database window. Then, double-click on Design View. Using the finished form shown in Form view in Figure D as a guide, resize the form and add the appropriate checkbox, line and command button controls. Set the checkbox labels and button captions appropriately. Then, set the same Form properties that you used from Table B, but set the Caption property to My Application Settings. Finally, change the control names using Table C and save the form as frmControlPanel.
Figure D: Users can set their tip preferences using this form.
Table C: frmControlPanel control names
Retrieve and update the tip settings
At this point, we're ready to add the code that manipulates our tip-related registry keys. Click the Code button and then enter the procedures shown in Listing C.
Sub CheckboxUpdate() chkTipStartup = GetSetting("MyApplication", _ "TipSettings", "ShowTips", -1) chkHumorous = GetSetting("MyApplication", _ "TipSettings", "ShowHumorous", -1) End SubSub ApplySettings() SaveSetting "MyApplication", _ "TipSettings", "ShowTips", _ chkTipStartup SaveSetting "MyApplication", _ "TipSettings", "ShowHumorous", _ chkHumorous End Sub
The first procedure ensures that the checkbox controls display the correct states that reflect the
ShowHumorous keys. If the keys don't exist in the registry, defaults of -1 are returned so that the checkboxes are displayed as being selected. The
CheckboxUpdate procedure should run when the form is opened, so choose Form from the Object dropdown list and ensure that Load is selected from the Procedure dropdown list. Then, enter CheckboxUpdate at the insertion point.
ApplySettings procedure saves the current values of chkTipStartup and chkHumorous to the appropriate registry keys. Users can change the settings and commit them by clicking the Apply button. Whatever state the checkboxes are in will also be saved when users click the OK button, which will then close the form.
Let's enter the code for the command buttons. First, choose cmdApply from the Object dropdown list and enter ApplySettings in the Click event procedure. Next, choose cmdOK from the Object dropdown list and enter
ApplySettings DoCmd.Close acForm, Me.Name
at the insertion point.
Remove your custom settings from the registry to restore the default options
One way to allow users to re-enable the tip feature is to use the
SaveSetting statement to save a value other than 0 to the
ShowTips key, as we did in Listing C. However, since the
GetSetting function we used in Listing C returns
True default values, you can accomplish the same result by deleting the
ShowTips key altogether. In fact, we'll use the
DeleteSetting statement to remove the entire
MyApplication registry entry, effectively restoring all of the tip options to their defaults.
First, choose cmdReset from the Object dropdown list and enter the code shown in Listing D at the insertion point. We trap for error number 5, which occurs when you try to delete a registry key that doesn't exist. Save and close the module, then save the form and switch to Form view.
Listing D: Code to delete registry keys
On Error GoTo ErrorHandling DeleteSetting "MyApplication" CheckboxUpdate Exit Sub ErrorHandling: If Err = 5 Then Resume Next Else MsgBox Err & _ ": " & Err.Description End If
Test the control panel form
At this point, your form resembles the one shown in Figure D. Click the Reset To Defaults button and you'll see that both check boxes become selected, indicating that the tip form can now be opened. Close frmControlPanel and open frmTipOfTheDay--it should open without any problems.
Rotate the tips
At this point, we've given users control of whether the tip form is displayed. Now, we need to add the final code that allows them to move between tips and to screen out humorous entries. To keep our code as simple as possible, we'll use the DoCmd object to move between records.
First, switch to Design view and click the Code button. Press [Ctrl][End] to move to the end of the existing code and then enter the procedure shown in Listing E. This procedure changes the tip displayed in the tip form by moving forward or backward through its underlying recordset.
Listing E: Code to move between records
Sub ChangeTip(bytDirection As Byte) Dim blnShowHumorous As Boolean Dim blnFoundTip As BooleanOn Error GoTo ErrorHandlingDo Until blnFoundTip = True If bytDirection = 0 Then DoCmd.GoToRecord , , acNext Else DoCmd.GoToRecord , , acPrevious End If blnShowHumorous = GetSetting("MyApplication", _ "TipSettings", "ShowHumorous", "-1") If blnShowHumorous = "0" And Me.Humorous = -1 Then blnFoundTip = False Else blnFoundTip = True End If Loop Exit SubErrorHandling: Select Case Err Case 2105 If bytDirection = 0 Then DoCmd.GoToRecord , , acFirst Else DoCmd.GoToRecord , , acLast End If Resume Next Case Else MsgBox Err & ": " & Err.Description End Select End Sub
The first If statement and the
bytDirection variable determine the direction that records are cycled through. The
Do Until...Loop continues moving through records if the selected record is flagged as Humorous and the user has specified that they don't want to see humorous entries, as defined by the variable
blnShowHumorous. When the code tries to move past either end of the recordset, an error of 2105 is raised, and our simple error trapping directs the focus to the first or last record of the recordset as appropriate.
To enable the navigation between tips, we need to pass a value of 0 or 1 to the ChangeTip procedure. We'll start with the code for the Next button. First, choose cmdNext from the Object dropdown list. Then, enter
at the insertion point. Next, select cmdBack and enter the same thing, but change the 0 to 1.
The last bit of code we'll add checks the registry for the TipID value of the last tip that the tip form displayed. Then, the procedure will find that record and simply move to the next one in the recordset. To add this code, replace the existing code in the Form object's Load event procedure with the code shown in Listing F. The error number we trap for, 3077, occurs when the
FindFirst method is called and there is no
LastTip registry key. This will be the case the first time the form is opened or after a user has clicked the Reset button on frmControlPanel. In such a case, we assume that the first record should be displayed and our code handles the error accordingly.
Listing F: Code to display next tip in rotation
On Error GoTo ErrorHandlingIf GetSetting("MyApplication", _ "TipSettings", "ShowTips") = "0" Then DoCmd.Close acForm, "frmTipOfTheDay" Exit Sub End IfMe.RecordsetClone.FindFirst _ "[TipID] = " & GetSetting("MyApplication", _ "TipSettings", "LastTip") Me.Bookmark = Me.RecordsetClone.BookmarkChangeTip (0) DoCmd.GoToControl ("cmdClose") Exit SubErrorHandling: Select Case Err Case 3077 DoCmd.GoToRecord , , acFirst Exit Sub Case Else MsgBox Err & ": " & Err.Description End Select
The final touches
Now that the hard part is over, we'll do a few minor adjustments to make the tip form more attractive and hide the tip table from users. First, save and close the form's module. Then, select cmdBack, display the command button's property sheet and click in the Picture text box. Next, click the Build button to the right of the text box and select an appropriate graphic from the Available Pictures list box, as shown in Figure E. Click OK to finish the selection and then use the same process to select graphics for cmdNext and cmdClose.
Figure E: Spruce up the tip form by adding graphics to the command buttons.
When you've finished adding the button pictures, save and close the form. Then, right-click on tblTips on the Tables sheet of the Database window and choose Properties from the shortcut menu. Select the Hidden check box and then click OK to keep the table hidden from view.
Implementing the tip feature
We've shown you one way to set up data and a form to display rotating messages when a form is opened. We've also shown you how to effectively put the Windows registry to work to store customized settings. You can combine these techniques with the methods described in the September 2000 article, "Create a polished application with customized startup options", to create a fully customized Tip of the Day feature.
Copyright © 2000 Element K Content LLC. All rights reserved. Reproduction in whole or in part in any form or medium without express written permission of Element K Content LLC is prohibited. Element K is a service mark of Element K LLC.