Results 1 to 5 of 5
  1. #1
    Star Lounger
    Join Date
    May 2006
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    The line
    DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70
    brings up the Find and Replace dialog.

    The default value for the Macth field is 'Whole field'

    How can I automatically set the option Match to 'Start of Field' without clicking on it?

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    You can use SendKeys for this:

    SendKeys "%hs%n"
    RunCommand acCmdFind

    See MSKB article ACC2000: How to Set Defaults for the Find and Replace Dialog Box for the accelerator keys in the English language version of Access.

    Added later: I originally had "%ha%n", it should have been "%hs%n%.

  3. #3
    Star Lounger
    Join Date
    May 2006
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks so much for the right answer and such a quick reply.

    Your solution was almost perfect, but I had to change the %ha%n to %hs%n, but it was the link to the MS article that provided the details.

    Code:
    SendKeys "%hs%n"
    RunCommand acCmdFind
    It is confusing to see the SendKeys before calling the Find and Replace form, but I can live with that.

    ===============================================
    Here is an excerpt from the link you provided:
    Code:
    The following table lists which keystrokes to send to select various items in the Find and Replace dialog box:
    
       Option					   Setting			 Keystrokes
       -----------------------------------------------------------
      Match						Any Part of Field   %ha
      Match						Start of Field	  %hs
      Match Case				   <selected>		  %c
      Search Fields as Formatted   <selected>		  %o
      Search					   Up				  %su
      Search					   Down				%sd
    				
    
    You can combine these keystrokes to make multiple selections. For example, the following actions open the Find and Replace dialog box with Start Of Field selected in the Match box; select Up in the Search box; and set the focus to the Find What box:
    
       Action	   Action Argument
       ------------------------------
       SendKeys	 Keystrokes: %hs%su%n
    					   Wait: No
       RunCommand   Command: Find

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts
    You're correct, I forgot to check your question again after copying the SendKeys code from the article.
    I have corrected my original reply.

    SendKeys has to be called before displaying the dialog. SendKeys places the keystrokes into the keyboard buffer, waiting to be picked up by whatever comes next, in this case the dialog.
    If you placed SendKeys after the dialog, the dialog wouldn't receive the keystrokes because the dialog has to be closed by the user before the next instruction is executed.

  5. #5
    Star Lounger
    Join Date
    May 2006
    Posts
    51
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks also for the explanation about the SendKeys.

    That makes sense now that you tell the background story.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •