By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,461 Members | 2,184 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,461 IT Pros & Developers. It's quick & easy.

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

Shakss2
P: 19
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
Jan 11 '08 #1
Share this Question
Share on Google+
10 Replies


puppydogbuddy
Expert 100+
P: 1,923
see this link for answers for this question in another thread:
http://www.thescripts.com/forum/thread201087.html
Jan 12 '08 #2

ADezii
Expert 5K+
P: 8,619
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
Expand|Select|Wrap|Line Numbers
  1. 'Set to General Search - Part of Field
  2. Application.SetOption "Default Find/Replace Behavior", 1
  3.  
  4.   'do whatever you like in here, but Reset Option at some point
  5.  
  6. 'Reset to Fast Search - Whole Field
  7. Application.SetOption "Default Find/Replace Behavior", 0
Jan 13 '08 #3

missinglinq
Expert 2.5K+
P: 3,532
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:

Expand|Select|Wrap|Line Numbers
  1. 'Define global variable
  2. Public intEntryBehavior As Integer
  3.  
  4. 'Get original setting
  5. intEntryBehavior = Application.GetOption("Behavior Entering Field")
  6.  
  7. 'Set option you want
  8. Application.SetOption "Behavior Entering Field", 1
  9.  
  10. 'Reset to original setting
  11. Application.SetOption "Behavior Entering Field", intEntryBehavior
  12.  
Linq ;0)>
Jan 13 '08 #4

ADezii
Expert 5K+
P: 8,619
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:

Expand|Select|Wrap|Line Numbers
  1. 'Define global variable
  2. Public intEntryBehavior As Integer
  3.  
  4. 'Get original setting
  5. intEntryBehavior = Application.GetOption("Behavior Entering Field")
  6.  
  7. 'Set option you want
  8. Application.SetOption "Behavior Entering Field", 1
  9.  
  10. 'Reset to original setting
  11. Application.SetOption "Behavior Entering Field", intEntryBehavior
  12.  
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:
Expand|Select|Wrap|Line Numbers
  1. Screen.PreviousControl.SetFocus
  2.   SendKeys "{TAB 2}": SendKeys "{UP 2}"
  3.   SendKeys "+{TAB 2}"
  4. DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70
Jan 13 '08 #5

missinglinq
Expert 2.5K+
P: 3,532
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)>
Jan 13 '08 #6

ADezii
Expert 5K+
P: 8,619
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.
Jan 13 '08 #7

missinglinq
Expert 2.5K+
P: 3,532
As John Walton was wont to say, "Life's a mystery!"

Linq ;0)>
Jan 13 '08 #8

Shakss2
P: 19
Thanks a ton to ADezii and missinglinq....

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

Thanks and regards,
Shaq
Jan 16 '08 #9

ADezii
Expert 5K+
P: 8,619
As John Walton was wont to say, "Life's a mystery!"

Linq ;0)>
Was this the same John Boy Walton of The Waltons (LOL)?
Jan 17 '08 #10

missinglinq
Expert 2.5K+
P: 3,532
Nope! Was his daddy!

Linq ;0)>
Jan 17 '08 #11

Post your reply

Sign in to post your reply or Sign up for a free account.