Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    St. Marys, Ontario, Canada
    Posts
    270
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Command button to search a specific field

    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.

  2. #2
    Star Lounger
    Join Date
    Jan 2001
    Location
    Bethel, CT, USA
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Command button to search a specific field

    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.

  3. #3
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    St. Marys, Ontario, Canada
    Posts
    270
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Command button to search a specific field

    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.

  4. #4
    Star Lounger
    Join Date
    Jan 2001
    Location
    Bethel, CT, USA
    Posts
    58
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Command button to search a specific field

    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.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •