Tags: access, aceditmenu, acformbar, acmenuver70, current, database, docmddomenuitem, drop-down, field, focus, form, microsoft, mysql, oracle, search, selectsthe, specific, sql, user

Search only current using DoCmd.DoMenuItem acFormBar, acEditMenu, 10, , acMenuVer70

On Database » Microsoft Access

2,770 words with 2 Comments; publish: Fri, 06 Jun 2008 09:23:00 GMT; (250218.75, « »)

Hello,

I am trying to do a search on a specific field on a form. The user selects

the field they want to search from a drop-down and I set the focus to the

field and then I do "DoCmd.DoMenuItem acFormBar, acEditMenu, 10, ,

acMenuVer70". However, it trys to search all fields instead of only the

desired field which brings up an error on Find Next because the focus has

changed which prevents FindNext from working.

The DoCmd.FindRecord has the option acCurrent so is there a way to set the

option when using DoCmd.DoMenuItem?

Thanks,

Vic

All Comments

Leave a comment...

  • 2 Comments
    • If you are doing this from a command button, then the button has focus when

      you click it. The buttons is not attached to a field that can be searched.

      Try setting control back to the field that had focus before the button was

      clicked:

      Screen.PreviousControl.SetFocus

      Then add the Search line.

      You will need error handling, e.g. there may not be any previous control.

      Allen Browne - Microsoft MVP. Perth, Western Australia.

      Tips for Access users - http://allenbrowne.com/tips.html

      Reply to group, rather than allenbrowne at mvps dot org.

      "Vic Spainhower" <vicNoSpam.ms-access.todaysummary.com.perfected.com> wrote in message

      news:OKYRC27WFHA.164.ms-access.todaysummary.com.TK2MSFTNGP10.phx.gbl...

      > I am trying to do a search on a specific field on a form. The user

      > selects the field they want to search from a drop-down and I set the focus

      > to the field and then I do "DoCmd.DoMenuItem acFormBar, acEditMenu, 10, ,

      > acMenuVer70". However, it trys to search all fields instead of only the

      > desired field which brings up an error on Find Next because the focus has

      > changed which prevents FindNext from working.

      > The DoCmd.FindRecord has the option acCurrent so is there a way to set the

      > option when using DoCmd.DoMenuItem?

      #1; Fri, 06 Jun 2008 09:24:00 GMT
    • > Try setting control back to the field that had focus before the button was

      > clicked:

      > Screen.PreviousControl.SetFocus

      > Then add the Search line.

      > You will need error handling, e.g. there may not be any previous control.

      I added support for the 2173 error to the form error event handling and

      when I set focus to previous control I get an error. So I tried calling

      a routine to explicitly set focus to the field I am trying to search on

      and that doesn't work either. The only way I can do multiple searches

      on the same field is to click into the field before pressing findnext.

      This used to work and I don't know when or what made it stop working.

      Appreciate any help received.

      Vic

      #2; Fri, 06 Jun 2008 09:25:00 GMT