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

Command button to open Find dialog

P: n/a
How can I program a command button on a form to bring up the standard "Find
and Replace" dialog on click?

Separate but related: how do you run menu commands (e.g. "Edit" "Find") from
VB?

Thanks in advance!

Alex

Mar 3 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Alex Chun wrote:
How can I program a command button on a form to bring up the standard "Find
and Replace" dialog on click?

Separate but related: how do you run menu commands (e.g. "Edit" "Find") from
VB?


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Answer to both questions: use the RunCommand method of the DoCmd
object. E.g.:

DoCmd.RunCommand acCmdFind

The cursor has to be in the control you want to search.

See the VBA Help article on RunCommand for a list of other "menu"
commands available thru RunCommand.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBRAiqV4echKqOuFEgEQJzwACfSo0pZmYX2dfYEgGsfUC1a1 6weXUAn2Z0
vVgzUoZM/4I8VAa0GAg+eYY/
=wa69
-----END PGP SIGNATURE-----
Mar 3 '06 #2

P: n/a
This works, except that the command button -- which is unsearchable -- now
has the focus. Is there an easy way to program the button to search the
field that the cursor was in?

Thanks again.

Alex
"MGFoster" <me@privacy.com> wrote in message
news:9T***************@newsread1.news.pas.earthlin k.net...
Alex Chun wrote:
How can I program a command button on a form to bring up the standard
"Find and Replace" dialog on click?

Separate but related: how do you run menu commands (e.g. "Edit" "Find")
from VB?


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Answer to both questions: use the RunCommand method of the DoCmd
object. E.g.:

DoCmd.RunCommand acCmdFind

The cursor has to be in the control you want to search.

See the VBA Help article on RunCommand for a list of other "menu"
commands available thru RunCommand.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBRAiqV4echKqOuFEgEQJzwACfSo0pZmYX2dfYEgGsfUC1a1 6weXUAn2Z0
vVgzUoZM/4I8VAa0GAg+eYY/
=wa69
-----END PGP SIGNATURE-----

Mar 3 '06 #3

P: n/a
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Assuming the user had put the cursor in the control they wanted to
search, in the Command Button OnClick event put this:

dim ctl as control

set ctl = screen.previouscontrol
ctl.setfocus

Or if you know the control you want the search to be on just indicate
that control:

Me!SearchTextBox.SetFocus
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBRAkBFoechKqOuFEgEQJBgwCgiiDl8qedn4WSsnYdl3i9Wj YfgjYAnA5o
Cg3iC0IvY2MT7EnRoY9wYNxV
=GtQz
-----END PGP SIGNATURE-----

Alex Chun wrote:
This works, except that the command button -- which is unsearchable -- now
has the focus. Is there an easy way to program the button to search the
field that the cursor was in?

Thanks again.

Alex
"MGFoster" <me@privacy.com> wrote in message
news:9T***************@newsread1.news.pas.earthlin k.net...
Alex Chun wrote:
How can I program a command button on a form to bring up the standard
"Find and Replace" dialog on click?

Separate but related: how do you run menu commands (e.g. "Edit" "Find")
from VB?


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Answer to both questions: use the RunCommand method of the DoCmd
object. E.g.:

DoCmd.RunCommand acCmdFind

The cursor has to be in the control you want to search.

See the VBA Help article on RunCommand for a list of other "menu"
commands available thru RunCommand.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBRAiqV4echKqOuFEgEQJzwACfSo0pZmYX2dfYEgGsfUC1a1 6weXUAn2Z0
vVgzUoZM/4I8VAa0GAg+eYY/
=wa69
-----END PGP SIGNATURE-----


Mar 4 '06 #4

P: n/a
put the command button in the form's Header or Footer section, and run
MGFoster's original code from it, as

DoCmd.RunCommand acCmdFind

just put your cursor in the control you want to search before clicking the
button. because the button is not in the Detail section, Access still reads
the "focus" as being on the control, not the command button.

hth
"Alex Chun" <ac***@nospam.u.washington.edu> wrote in message
news:du**********@gnus01.u.washington.edu...
This works, except that the command button -- which is unsearchable -- now
has the focus. Is there an easy way to program the button to search the
field that the cursor was in?

Thanks again.

Alex
"MGFoster" <me@privacy.com> wrote in message
news:9T***************@newsread1.news.pas.earthlin k.net...
Alex Chun wrote:
How can I program a command button on a form to bring up the standard
"Find and Replace" dialog on click?

Separate but related: how do you run menu commands (e.g. "Edit" "Find")
from VB?


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Answer to both questions: use the RunCommand method of the DoCmd
object. E.g.:

DoCmd.RunCommand acCmdFind

The cursor has to be in the control you want to search.

See the VBA Help article on RunCommand for a list of other "menu"
commands available thru RunCommand.
--
MGFoster:::mgf00 <at> earthlink <decimal-point> net
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBRAiqV4echKqOuFEgEQJzwACfSo0pZmYX2dfYEgGsfUC1a1 6weXUAn2Z0
vVgzUoZM/4I8VAa0GAg+eYY/
=wa69
-----END PGP SIGNATURE-----


Mar 4 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.