Storing dialog box settings

Although creating a dialog box is easy, you need to first think about how you want to deal with the settings that the user chooses. If you want your dialog box to remember settings from one session to the next, you need to store those settings in some sort of table. Otherwise, all the user's settings will be forgotten by Access each time the user closes the database.

The table that you create for storing dialog box settings needs only one record, with a field to store each dialog box setting that needs to be remembered. In this chapter, I show you how to create a fancy dialog box for the SkipLabels procedure I create in Chapter 8. I show you how to make it remember which report the user last used for printing labels and how many labels the user skipped on each run. This will make it a little easier for the user to reuse settings in the dialog box.

For this example, create a tiny table that stores the name of the report as Text and the number of labels last skipped as a Number. Figure 9-2 shows the structure of the table that I use here. You don't need to define a primary key in this table because the table will never contain any more than one record. I'll name the table SettingsTable.

Figure 9-2:

Structure of the Settings Table table.

Field Marne | Data Type

Description

ReportName Text Settings table for SkipLabel dialog box.

LabelsToSkip Number Number of labels to skip

_Field Properties_

Field Marne | Data Type

Description

ReportName Text Settings table for SkipLabel dialog box.

LabelsToSkip Number Number of labels to skip

_Field Properties_

General 1 Lookup

Field Size

Byte

Format

Decimal Places

Auto

Input Mask

Caption

Default Value

0

Validation Rule

Validation Text

Required

No

Indexed

Mo

Smart Tags

After you close and save the table, you need to open that table and type in the value of at least one field. That's because when you bind a dialog box to that table later, it will work only if the table already contains one record. For example, Figure 9-3 shows one record that I typed into the SettingsTable table. The blank record beneath the filled record isn't an actual record in the table. That empty record appears only as a placeholder for any new record that you want to add to the table in Datasheet view.

Figure 9-3:

One table record stores dialog box settings.

Figure 9-3:

One table record stores dialog box settings.

You can see an example of using the SettingsTable values in a dialog box a little later in this chapter. For now, master how to create a dialog box in the first place.

0 0

Post a comment