Using the Find Command with a Command Button

  • Follow


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)
-- 
Thanks in advance!

Sherwood
0
Reply Utf 3/19/2007 11:40:12 PM


"Sherwood" wrote:

> 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)
> -- 
> Thanks in advance!
> 
> Sherwood

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
0
Reply Utf 3/19/2007 11:49:00 PM


Thanks.  That worked great!
-- 
Sherwood


"Dave" wrote:

> 
> 
> "Sherwood" wrote:
> 
> > 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)
> > -- 
> > Thanks in advance!
> > 
> > Sherwood
> 
> 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
0
Reply Utf 3/20/2007 12:03:03 AM

2 Replies
681 Views

(page loaded in 0.048 seconds)


Reply: