Using the Find Command with a Command Button

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)
 
G

Guest

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
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Modifying Command Button 2
Comand Button 2
"Delete Record" command button woes 4
Error 2237 8
pop = yes problem 1
Command button - copy record 1
delete command button 1
Find & Replace Box default find 1

Top