Results 1 to 4 of 4

Basic Search button in Access Form

This is a discussion on Basic Search button in Access Form within the Microsoft Access forums, part of the Question Forums category; How do I create a search button for Access in Form view(to seach a field that has your cursor in ...

  1. #1
    New Member
    Join Date
    Oct 2005
    Posts
    11

    Default Basic Search button in Access Form

    How do I create a search button for Access in Form view(to seach a field that has your cursor in it?
    I tried searching for it here, but could not find an answer, as well as you may tell, I have no programming skills, I know only the basics.
    If you can help I would appreciate it! Thanks!

  2. #2
    MrExcel MVP Andrew Fergus's Avatar
    Join Date
    Sep 2004
    Location
    New Zealand
    Posts
    5,236

    Default

    Hi
    Depending on your version of Access there is already a search function. Select the field you wish to search, press the Ctrl and F keys together. A dialogue box will appear asking what you want to search for and what sort of match you want. Will this suffice?
    Andrew
    ~ >*()))><(


    I'd rather have a full bottle in front of me than a full frontal lobotomy.

  3. #3
    New Member
    Join Date
    Oct 2005
    Posts
    11

    Default

    Thanks for the reply, but is there an easy way to put a button on the form to bring up a search?
    This search feature is not for me, but an even more computer illiterate person than(if you can imagine!), and I want it as straight forward as possible.

    They see a button with binoculars on it..they know it's a search button.
    Thanks for your help!

  4. #4
    MrExcel MVP Andrew Fergus's Avatar
    Join Date
    Sep 2004
    Location
    New Zealand
    Posts
    5,236

    Default

    You've got quite a few options depending on where you want to go with this. The 2 simplest methods I use are described below.

    1. Standard Windows Pop-up
    To activate the standard search feature per my first post but using a Button with binoculars, go into the form design screen and create a new button. When the command button wizard appears, choose the 'Record Navigation' option, then the 'Find Record' option -> click Finish. This will have the same effect as pressing Ctrl-F without pressing those keys.

    2. Using a combo box
    Another way of achieving this is by using a combo box in the header of the form (or in a new pop-up form when you click the binoculars) that lists the records you wish to search. This way the user can start typing in what they are seeking and the combo box will find the record automatically. The VBA code for doing this in the form header looks like this :

    Code:
    Private Sub MyComboBoxName_AfterUpdate()
    
    On Error GoTo Err_ErrorHandler
    
    Dim ItemSelected As String
    
        ItemSelected = Forms!MyFormName.MyComboBoxName
        MyComboBoxName = Null
        Me.Filter = "MySearchField = '" & ItemSelected & "'"
        Me.FilterOn = True
    
    Err_ErrorHandler:
        Exit Sub
    
    End Sub
    Be sure to use the actual form and field names where I have used 'MyComboBoxName', 'MySearchField' and 'MyFormName'. This code is placed in the after update section / property of the combo box. Please note that code will need to be modified if you use a pop-up or intermediate search form (instead of putting it into the form header / footer) or if the combo box returns a value instead of a string.

    This code will bring the record selected in the combo box to the fore on the current form by applying a filter - IMO it has the same effect / outcome as a search and my users like it.

    HTH, Andrew
    ~ >*()))><(


    I'd rather have a full bottle in front of me than a full frontal lobotomy.

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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


DMCA.com