code for Find and Replace to default "a part of field"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Shakss2
    New Member
    • Dec 2007
    • 19

    code for Find and Replace to default "a part of field"

    I have a form, where I can activate the search and replace dialogbox when
    pressing a button.

    My problem is that the dialogbox opens with the default that it should
    search for full match only, and I want it to open with default "a part of
    field".

    I did change it to default "A part of the field"?
    by going to Tools -> Options menu to open the "Options" dialog window. Select the "Edit/Find" tab. Select the "General Search" option button.

    But when I give this to any 1 else to test or for users it again defaults to "Whole field". I cant ask the users to change it at there end.

    Can any 1 pls help me with some code which can do this for me.
    Where it defaults to "a part of field" for all users who will use this application.

    Thanks a ton in advance.

    Shaq
  • puppydogbuddy
    Recognized Expert Top Contributor
    • May 2007
    • 1923

    #2
    see this link for answers for this question in another thread:

    Comment

    • ADezii
      Recognized Expert Expert
      • Apr 2006
      • 8834

      #3
      Originally posted by Shakss2
      I have a form, where I can activate the search and replace dialogbox when
      pressing a button.

      My problem is that the dialogbox opens with the default that it should
      search for full match only, and I want it to open with default "a part of
      field".

      I did change it to default "A part of the field"?
      by going to Tools -> Options menu to open the "Options" dialog window. Select the "Edit/Find" tab. Select the "General Search" option button.

      But when I give this to any 1 else to test or for users it again defaults to "Whole field". I cant ask the users to change it at there end.

      Can any 1 pls help me with some code which can do this for me.
      Where it defaults to "a part of field" for all users who will use this application.

      Thanks a ton in advance.

      Shaq
      [CODE=vb]
      'Set to General Search - Part of Field
      Application.Set Option "Default Find/Replace Behavior", 1

      'do whatever you like in here, but Reset Option at some point

      'Reset to Fast Search - Whole Field
      Application.Set Option "Default Find/Replace Behavior", 0[/CODE]

      Comment

      • missinglinq
        Recognized Expert Specialist
        • Nov 2006
        • 3533

        #4
        I tried using this kind of code to change one of Access' default behaviors (don't remember which one, off hand) and ran into the same problem, I think, that you'll have here; changes to the Default behavior of Find/Replace don't take effect until Access is closed and then reopened. While you can use this to change the default, it won't take effect until the next time Access is opened, and you can't really use the code to reset the behavior. Whichever setting is executed last in the original session is the one that will appear in the next session.

        I understand the OP's not wanting to change the Default behavior on users machines, but I don't really see a way around that. I used to have a hack using SendKeys to do this, but it was so buggy (as SendKeys tends to be) I stopped using it. It's probably better letting the users know that they need to change this setting than to merely change it with code, but in reality, most probably don't even know it exists!

        The other thing is that even if the code worked as desired, you'd only be guessing at what the user originally had the default set to. It could have already been set to "find any part" and you'd be changing it, which isn't desirable. The way around this, for changing defaults that do take effect without closing/opening Access, is to use the GetOption property, assign it to a global variable (of Integer Datatype) and use it to reset the default.

        Behavior Entering Field is one such default that takes effect immediately:

        [CODE=vb]'Define global variable
        Public intEntryBehavio r As Integer

        'Get original setting
        intEntryBehavio r = Application.Get Option("Behavio r Entering Field")

        'Set option you want
        Application.Set Option "Behavior Entering Field", 1

        'Reset to original setting
        Application.Set Option "Behavior Entering Field", intEntryBehavio r
        [/CODE]
        Linq ;0)>

        Comment

        • ADezii
          Recognized Expert Expert
          • Apr 2006
          • 8834

          #5
          Originally posted by missinglinq
          I tried using this kind of code to change one of Access' default behaviors (don't remember which one, off hand) and ran into the same problem, I think, that you'll have here; changes to the Default behavior of Find/Replace don't take effect until Access is closed and then reopened. While you can use this to change the default, it won't take effect until the next time Access is opened, and you can't really use the code to reset the behavior. Whichever setting is executed last in the original session is the one that will appear in the next session.

          I understand the OP's not wanting to change the Default behavior on users machines, but I don't really see a way around that. I used to have a hack using SendKeys to do this, but it was so buggy (as SendKeys tends to be) I stopped using it. It's probably better letting the users know that they need to change this setting than to merely change it with code, but in reality, most probably don't even know it exists!

          The other thing is that even if the code worked as desired, you'd only be guessing at what the user originally had the default set to. It could have already been set to "find any part" and you'd be changing it, which isn't desirable. The way around this, for changing defaults that do take effect without closing/opening Access, is to use the GetOption property, assign it to a global variable (of Integer Datatype) and use it to reset the default.

          Behavior Entering Field is one such default that takes effect immediately:

          [CODE=vb]'Define global variable
          Public intEntryBehavio r As Integer

          'Get original setting
          intEntryBehavio r = Application.Get Option("Behavio r Entering Field")

          'Set option you want
          Application.Set Option "Behavior Entering Field", 1

          'Reset to original setting
          Application.Set Option "Behavior Entering Field", intEntryBehavio r
          [/CODE]
          Linq ;0)>
          I used to have a hack using SendKeys to do this, but it was so buggy (as SendKeys tends to be) I stopped using it.
          These Key Sequences seem to work fairly well:
          [CODE=vb]
          Screen.Previous Control.SetFocu s
          SendKeys "{TAB 2}": SendKeys "{UP 2}"
          SendKeys "+{TAB 2}"
          DoCmd.DoMenuIte m acFormBar, acEditMenu, 10, , acMenuVer70[/CODE]

          Comment

          • missinglinq
            Recognized Expert Specialist
            • Nov 2006
            • 3533

            #6
            What version of Access are you running? Your code doesn't work for me in ACC2003. But like I said, I had other SendKeys code that worked sometimes and didn't work at other times. There's nothing else that has to be set for SendKeys to work, is there?

            Linq ;0)>

            Comment

            • ADezii
              Recognized Expert Expert
              • Apr 2006
              • 8834

              #7
              Originally posted by missinglinq
              What version of Access are you running? Your code doesn't work for me in ACC2003. But like I said, I had other SendKeys code that worked sometimes and didn't work at other times. There's nothing else that has to be set for SendKeys to work, is there?

              Linq ;0)>
              Ironically enough, it was tested in Access 2003.

              Comment

              • missinglinq
                Recognized Expert Specialist
                • Nov 2006
                • 3533

                #8
                As John Walton was wont to say, "Life's a mystery!"

                Linq ;0)>

                Comment

                • Shakss2
                  New Member
                  • Dec 2007
                  • 19

                  #9
                  Thanks a ton to ADezii and missinglinq....

                  It made my life easy...
                  it works as said by you guys.

                  Thanks and regards,
                  Shaq

                  Comment

                  • ADezii
                    Recognized Expert Expert
                    • Apr 2006
                    • 8834

                    #10
                    Originally posted by missinglinq
                    As John Walton was wont to say, "Life's a mystery!"

                    Linq ;0)>
                    Was this the same John Boy Walton of The Waltons (LOL)?

                    Comment

                    • missinglinq
                      Recognized Expert Specialist
                      • Nov 2006
                      • 3533

                      #11
                      Nope! Was his daddy!

                      Linq ;0)>

                      Comment

                      Working...