• Command button to search a specific field

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Command button to search a specific field

    Author
    Topic
    #352737

    I have created a form and want to put a command button on it to search a specific field (let’s say a Lastname). How do I do this?

    As a quick aside, I am truly amazed at the knowledge assembled here. I don’t understand many of the answers (I don’t know visual basic), but everyone has always been patient with me and I appreciate your helping somebody with a desire to get better in Access achieve his goal.

    Viewing 0 reply threads
    Author
    Replies
    • #513995

      I’m not sure what you really want to do.
      Do you want to go to a record when data is found?
      Or, find out if data exists in another record?
      Or, see a list of existing entries for selection, as in a combo box?
      Also, a little less user friendly, but “Find” on the “Edit” dropdown menu will search any field for whatever you want.

      • #514026

        When I click on the button I want the Find dialog box to come up with the field I want in the “Look in” textbox, regardless what field I was in in the form. That way I can enter the criterium and click on find next and it will find the record I want, which in my example was somebody with a certain last name.

        • #514194

          John,
          Sorry I took so long.
          The simplest way to do what you want is to write a macro.
          Open a New macro.
          On the first line in the Action column, select GoToControl, then in the Command box on the lower portion of the macro window, enter the name of the field you want to search.
          On the second line in the Action column, select RunCommand, and in the Command box, enter Find.
          Save the Macro.
          Open your form in design view, create a button, and when the button design window prompts you, select Category: Miscellaneous, Action: Run Macro. On the next step, select the name of the macro you just saved. Step through the rest of the wizard and your done.
          When you click the button, your field to search will become the active field and the Find dialog will open with it selected. The only drawback to this method is that when you close the Find, you are still in the field to search. If there is a way to return the focus to a previous control outside of VBA, I don’t know what it is.
          Also, the Find dialog box will open with the default Match: Whole Field. If you want to change that to Any Part of Field, insert the Action: SendKeys between the other two with Keystrokes: %ha%n, Wait: No.
          Microsoft has more details on this method at: http://support.microsoft.com/support/kb/ar…s/Q120/9/12.asp
          Hope this helps.

    Viewing 0 reply threads
    Reply To: Command button to search a specific field

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: