Command button to open Find dialog

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Alex Chun

    Command button to open Find dialog

    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



  • MGFoster

    #2
    Re: Command button to open Find dialog

    Alex Chun wrote:[color=blue]
    > 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?[/color]

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

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

    DoCmd.RunComman d 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:::mgf0 0 <at> earthlink <decimal-point> net
    Oakland, CA (USA)

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

    iQA/AwUBRAiqV4echKq OuFEgEQJzwACfSo 0pZmYX2dfYEgGsf UC1a16weXUAn2Z0
    vVgzUoZM/4I8VAa0GAg+eYY/
    =wa69
    -----END PGP SIGNATURE-----

    Comment

    • Alex Chun

      #3
      Re: Command button to open Find dialog

      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:9T1Of.599$ x94.467@newsrea d1.news.pas.ear thlink.net...[color=blue]
      > Alex Chun wrote:[color=green]
      >> 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?[/color]
      >
      > -----BEGIN PGP SIGNED MESSAGE-----
      > Hash: SHA1
      >
      > Answer to both questions: use the RunCommand method of the DoCmd
      > object. E.g.:
      >
      > DoCmd.RunComman d 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:::mgf0 0 <at> earthlink <decimal-point> net
      > Oakland, CA (USA)
      >
      > -----BEGIN PGP SIGNATURE-----
      > Version: PGP for Personal Privacy 5.0
      > Charset: noconv
      >
      > iQA/AwUBRAiqV4echKq OuFEgEQJzwACfSo 0pZmYX2dfYEgGsf UC1a16weXUAn2Z0
      > vVgzUoZM/4I8VAa0GAg+eYY/
      > =wa69
      > -----END PGP SIGNATURE-----[/color]


      Comment

      • MGFoster

        #4
        Re: Command button to open Find dialog

        -----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.previous control
        ctl.setfocus

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

        Me!SearchTextBo x.SetFocus
        --
        MGFoster:::mgf0 0 <at> earthlink <decimal-point> net
        Oakland, CA (USA)

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

        iQA/AwUBRAkBFoechKq OuFEgEQJBgwCgii Dl8qedn4WSsnYdl 3i9WjYfgjYAnA5o
        Cg3iC0IvY2MT7En RoY9wYNxV
        =GtQz
        -----END PGP SIGNATURE-----

        Alex Chun wrote:[color=blue]
        > 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:9T1Of.599$ x94.467@newsrea d1.news.pas.ear thlink.net...
        >[color=green]
        >>Alex Chun wrote:
        >>[color=darkred]
        >>>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?[/color]
        >>
        >>-----BEGIN PGP SIGNED MESSAGE-----
        >>Hash: SHA1
        >>
        >>Answer to both questions: use the RunCommand method of the DoCmd
        >>object. E.g.:
        >>
        >> DoCmd.RunComman d 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:::mg f00 <at> earthlink <decimal-point> net
        >>Oakland, CA (USA)
        >>
        >>-----BEGIN PGP SIGNATURE-----
        >>Version: PGP for Personal Privacy 5.0
        >>Charset: noconv
        >>
        >>iQA/AwUBRAiqV4echKq OuFEgEQJzwACfSo 0pZmYX2dfYEgGsf UC1a16weXUAn2Z0
        >>vVgzUoZM/4I8VAa0GAg+eYY/
        >>=wa69
        >>-----END PGP SIGNATURE-----[/color]
        >
        >
        >[/color]

        Comment

        • tina

          #5
          Re: Command button to open Find dialog

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

          DoCmd.RunComman d 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" <achun@nospam.u .washington.edu > wrote in message
          news:duaff7$nhu $1@gnus01.u.was hington.edu...[color=blue]
          > 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:9T1Of.599$ x94.467@newsrea d1.news.pas.ear thlink.net...[color=green]
          > > Alex Chun wrote:[color=darkred]
          > >> 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?[/color]
          > >
          > > -----BEGIN PGP SIGNED MESSAGE-----
          > > Hash: SHA1
          > >
          > > Answer to both questions: use the RunCommand method of the DoCmd
          > > object. E.g.:
          > >
          > > DoCmd.RunComman d 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:::mgf0 0 <at> earthlink <decimal-point> net
          > > Oakland, CA (USA)
          > >
          > > -----BEGIN PGP SIGNATURE-----
          > > Version: PGP for Personal Privacy 5.0
          > > Charset: noconv
          > >
          > > iQA/AwUBRAiqV4echKq OuFEgEQJzwACfSo 0pZmYX2dfYEgGsf UC1a16weXUAn2Z0
          > > vVgzUoZM/4I8VAa0GAg+eYY/
          > > =wa69
          > > -----END PGP SIGNATURE-----[/color]
          >
          >[/color]


          Comment

          Working...