Using the Find Command with a Command Button

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Greetings,

I have a form with numerous fields that I am wanting to use the "Find"
command on. What I am wanting to do is use a command button on the form
labeled "Search". Whenever the user presses the Search button, I would like
the "Find" command to be executed for whatever field the cursor is currently
in. For instance, if the cursor is resting in the "First Name" field, then
when the user presses the "Search" button I would like the "Find and Replace"
dialog to appear so that they can't enter in a first name to search for. I
realize that there is the "Find and Replace" toolbar button that I can use,
but I haven't figured out how to use this with a command button. I have
tried to the following "DoCmd" line of code, but to no avail. Any
suggestions?

Call DoCmd.DoMenuItem(acFormBar, acEditMenu, acFindRecord, , acMenuVer70)
 
Sherwood said:
Greetings,

I have a form with numerous fields that I am wanting to use the "Find"
command on. What I am wanting to do is use a command button on the form
labeled "Search". Whenever the user presses the Search button, I would like
the "Find" command to be executed for whatever field the cursor is currently
in. For instance, if the cursor is resting in the "First Name" field, then
when the user presses the "Search" button I would like the "Find and Replace"
dialog to appear so that they can't enter in a first name to search for. I
realize that there is the "Find and Replace" toolbar button that I can use,
but I haven't figured out how to use this with a command button. I have
tried to the following "DoCmd" line of code, but to no avail. Any
suggestions?

Call DoCmd.DoMenuItem(acFormBar, acEditMenu, acFindRecord, , acMenuVer70)

Hi Sherwood,
Try pasting this into the OnClick event for your Search Button:

On Error GoTo Err_Find_Click

Screen.PreviousControl.SetFocus
DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70

Exit_Find_Click:
Exit Sub

Err_Find_Click:
MsgBox Err.DESCRIPTION
Resume Exit_Find_Click

Hope that helped.
Dave
 
Thanks. That worked great!
--
Sherwood


Dave said:
Hi Sherwood,
Try pasting this into the OnClick event for your Search Button:

On Error GoTo Err_Find_Click

Screen.PreviousControl.SetFocus
DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70

Exit_Find_Click:
Exit Sub

Err_Find_Click:
MsgBox Err.DESCRIPTION
Resume Exit_Find_Click

Hope that helped.
Dave
 
Back
Top