ACC: How to Set Defaults for the Find Dialog Box

ID: Q120912


The information in this article applies to:


SUMMARY

Moderate: Requires basic macro, coding, and interoperability skills.

This article describes how 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 Microsoft Access 1.x and 2.0      In Microsoft Access 7.0 and 97
  -------------------------------      ------------------------------
  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> 

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

   In Microsoft Access 97:

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

   In Microsoft Access 7.0, 2.0 and 1.x:

      SendKeys
         Keystrokes: %ha%n
         Wait: No
      DoMenuItem
         MenuBar: Form
         MenuName: Edit
         Command: Find 

This macro could then be assigned to a command button, a button on a form, or to an event on a form. When you run this macro, the Find dialog box will appear with Any Part Of Field selected in the Match box (or Where box in version 2.0 and 1.x). 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, even though it might seem that the call to open the dialog box should come first. However, if you place the call to open the dialog box first, the macro will run the RunCommand action and then wait for the dialog box to be closed before continuing to the next action (the SendKeys action), sending your keystrokes to the form.

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

In Microsoft Access 97 and 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 Microsoft Access 2.0 and 1.x:

   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 will open the Find dialog box with Start Of Field selected in the Match box, will clear the Search Only Current Field box (or select the All Fields option button in version 2.0) and will select Up in the Search:

   In Microsoft Access 97:

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

   In Microsoft Access version 7.0, 2.0 and 1.x:

      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," then click "Running," and next click the topic "Run a Macro." You can also ask the Microsoft Access 97 Office Assistant.


Keywords          : FmsHowto 
Version           : 1.0 1.1 2.0 7.0 97
Platform          : WINDOWS 
Issue type        : kbhowto 

Last Reviewed: April 7, 1999