Basic Search button in Access Form

Backwards Man

New Member
Joined
Oct 11, 2005
Messages
11
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!
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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 :)
 
Upvote 0
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!
 
Upvote 0
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 :)
 
Upvote 0

Forum statistics

Threads
1,213,551
Messages
6,114,273
Members
448,559
Latest member
MrPJ_Harper

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top