Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Setting Default for "Look In:" in Find/Replace Dialog 2

Status
Not open for further replies.

olliegracie

Technical User
May 25, 2006
6
US
I am trying to setup my Access 2003 form with a command button that will initiate the "Find and Replace" function and am almost there thanks to wonderful feedback from tek-tips users. My database contains thousands of records of people's names and addresses. What I mostly search on is the "Last Name" control or field. Therefore, I would like to have the command button, on clicking it, bring up the "Find" dialog box with the "Look In:" window set to "Last Name", and the "Match:" window set to "Any Part of Field." I have been successful in making "Any Part of Field" the default for the "Match:" window but would dearly love to be able to make the "Last Name" control be the default in the "Look In:" window.
 
olliegracie,
The "Look In:" should default to the field that has the focus when the Find/Replace form is opened.

Could you use [tt]Me.[Last Name].SetFocus[/tt] in your routine before you call the Find/Replace dialog?

Hope this helps,
CMP

[small]For the best results do what I'm thinking, not what I'm saying.[/small]
(GMT-07:00) Mountain Time (US & Canada)
 
Sorry on that last post. Was led to believe it addressed you problem; not so sure now, but worth a look anyway.

The Missinglinq

There's ALWAYS more than one way to skin a cat!
 
Okay, here it is:

Code:
Private Sub Command70_Click()
      Screen.PreviousControl.SetFocus
      SendKeys "%ha%n", False
      DoCmd.RunCommand acCmdFind
End Sub

You have to have the cursor in the field you want to search (just like invoking Search from the Menubar) but this code defaults it to Match "Any Part of Field".

The Missinglinq

There's ALWAYS more than one way to skin a cat!
 
If you want to eliminate having to click on the field first
replace:

Screen.PreviousControl.SetFocus

with

Me.YourLastNameControl.SetFocus

replacing YourLastNameControl with the actual name of your control.

The Missinglinq

There's ALWAYS more than one way to skin a cat!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top