ACC97: How to Set Defaults for the Find Dialog Box (120912)



The information in this article applies to:

  • Microsoft Access 97
  • Microsoft Access 1.0
  • Microsoft Access 1.1
  • Microsoft Access 2.0
  • Microsoft Access for Windows 95 7.0

This article was previously published under Q120912
Moderate: Requires basic macro, coding, and interoperability skills.

SUMMARY

This article describes two methods that you can use to invoke the Find dialog box with different default settings.

MORE INFORMATION

When you click Find on the Edit menu in Form view, the Find dialog box appears with the following default settings.
  In Access versions                   In version 7.0 and Access 97
  1.0, 1.1, and 2.0                         
  -------------------------------      ------------------------------
  Where: Match Whole Field             Search: All
  Search In: Current Field             Match: Whole Field
  Match Case: <clear>                  Match Case:  <clear>
  Search Fields As Formatted: <clear>  Search fields as formatted: <clear>
  Direction: Down                      Search only current field: <checked>
				

Method 1

In version 7.0 and Access 97, you can change these settings through the Edit/Find tab of the Options dialog box. To modify the settings through the Options dialog box, follow these steps:
  1. On the Tools menu, click Options and then click the Edit/Find tab.
  2. Under the "Default Find/Replace Behavior" section, change the option buttons to reflect the default behavior that you want.
The settings for each Search option are listed below.

Fast Search

In version 7.0 and Access 97
------------------------------
Search: All
Match: Whole Field
Match Case:  <clear>
Search fields as formatted: <clear>
Search only current field: <checked>
				

General Search

In version 7.0 and Access 97
------------------------------
Search: All
Match: Any Part of Field
Match Case:  <clear>
Search fields as formatted: <Not Available>
Search only current field: <clear>
				

Start of Field Search

In version 7.0 and Access 97
------------------------------
Search: All
Match: Start of Field
Match Case:  <clear>
Search fields as formatted: <clear>
Search only current field: <checked>
				

Method 2

You can also change these settings by invoking the Find dialog box with the DoMenuItem action (or RunCommand in Access 97) by using the SendKeys action to select different settings. For example, you can invoke the Find dialog box by using a macro with the following actions:
   In Access 97:

      SendKeys
         Keystrokes: %ha%n
         Wait: No
      RunCommand
         Command: Find

   In Access versions 2.0, 1.0, and 1.1, and in version 7.0:

      SendKeys
         Keystrokes: %ha%n
         Wait: No
      DoMenuItem
         MenuBar: Form
         MenuName: Edit
         Command: Find
				
This macro can then be assigned to a command button, to a button on a form, or to an event on a form. When you run this macro, the Find dialog box appears with Any Part Of Field selected in the Match box (or Where box in versions 2.0, 1.0, and 1.1). The keystrokes sent by the SendKeys action are:
  • ALT+H to select the Match box
  • "a" to select Any Part Of Field
  • and ALT+N to select the Find What box
The SendKeys action must come before the call to open the dialog box, although it may seem that the call to open the dialog box must come first. However, if you put the call to open the dialog box first, the macro runs the RunCommand action and then waits for the dialog box to close before the macro then continues to the next action (the SendKeys action). The SendKeys action sends your keystrokes to the form.

The following table lists the keystrokes to send to select various items in the Find dialog box.

In Access 97 and version 7.0:
   Option                       Setting             Keystrokes
   -----------------------------------------------------------
   Match                        Any Part of Field   %ha
   Match                        Start of Field      %hs
   Search Only Current Field    <cleared>           %e
   Match Case                   <selected>          %c
   Search Fields as Formatted   <selected>          %o
   Search                       Up                  %ru
   Search                       Down                %rd
				
In Access versions 2.0, 1.0, and 1.1:
   Option                       Setting             Keystrokes
   -----------------------------------------------------------
   Where                        Any Part Of Field   %ha
   Where                        Start Of Field      %hs
   Search In                    All Fields          %l
   Match Case                   <selected>          %s
   Search Fields As Formatted   <selected>          %o
   Direction                    Up                  %u
				
You can combine these keystrokes to make multiple selections. For example, the following actions open the Find dialog box with Start Of Field selected in the Match box. Then, the actions clear the Search Only Current Field box (or select the All Fields option in version 2.0). And then the actions select Up in the Search.
   In Access 97:

      SendKeys
         Keystrokes: %hs%e%ru%n
         Wait: No
      RunCommand
        Command: Find

   In Access versions 2.0, 1.0, and 1.1, and version 7.0:

      SendKeys
         Keystrokes: %hs%e%ru%n  (%hs%l%u%n in version 2.0 and 1.x)
         Wait: No
      DoMenuItem
         MenuBar: Form
         MenuName: Edit
         Command: Find
				

REFERENCES

For more information about the Find command, search the Help Index for "Find", and then "Finding data using Filters", or ask the Microsoft Access 97 Office Assistant.

For more information about the SendKeys action, search the Help Index for "SendKeys", and then "SendKeys Statement", or ask the Microsoft Access 97 Office Assistant.

For more information about running macros, search the Help Index for "Macros", click Running, and then click Run a Macro. You can also ask the Microsoft Access 97 Office Assistant.

Modification Type:MajorLast Reviewed:5/6/2003
Keywords:kbhowto KB120912