How to Add a Find Button to Your Access Database Form

I exploit MS Access (Home windows model 2003 nonetheless) for managing my necessary lists similar to my stock checklist for my eBay retailer. I deal primarily in one-of-a-kind items so I’ve, over time, over one thousand listings. That is a lot to hold observe of.

How to Add a Find Button to Your Access Database Form
How to Add a Find Button to Your Access Database Form

I wanted a great way to seek for and discover gadgets in varied fields. You should utilize the “[control] + f” keyboard shortcut, or you should utilize the Edit | Find menu, to search, however Access defaults to match the entire area and you’ve got to change it in order for you one thing else. I often don’t desire Match complete area. I often need Match any a part of area.

Some individuals like to use keyboard quick cuts. I am extra of a mouse individual if there may be a one-click method to do one thing. If there may be solely a many click on method that goes by way of menus, even utilizing solely two clicks similar to Edit | Find, then I’ll often resort to urgent [control] + f. However, this text will not be about whether or not one methodology is best than one other; this text is about providing one other method to search utilizing an Access database type.

F android version
F android model

So, I’ve developed a small button system that I exploit to discover gadgets in a specific area. I put the button to the proper of the sphere that it really works on. I can get to the discover dialog field arrange the way in which I would like it with one click on.

I add the button in type design through the use of the button device. In the event you select the Document Navigation | Find Document motion (a logical alternative), then the wizard offers you the next code (we are going to change the code later):

F android version
F android model

Display screen.PreviousControl.SetFocus

DoCmd.DoMenuItem acFormBar, acEditMenu, 10,, acMenuVer70

The primary line, Display screen.PreviousControl.SetFocus is good. It units the main target of what area shall be searched to the final area you touched. You possibly can have one button for all searches this fashion, however you should have to first click on on a area after which click on on the button. That is two clicks and never each person could perceive that’s the method it really works.

The second line, DoMenuItem, is restricted to every model of Access and means, on this case, the tenth merchandise within the Edit menu. You’d have to change this for each model of Access.

In the event you select the Document Navigation | Find Subsequent motion as an alternative, the wizard offers you the next code:

Display screen.PreviousControl.SetFocus


The FindNext is best than the DoMenuItem since you do not need to change the code for every model of Access. The dialog field that comes up whenever you click on the customized button on this article has a Find Subsequent button, so you actually do not want two buttons, Find and Find Subsequent. Find by itself will do properly.

The Access wizard coding is okay however you haven’t any management of the parameters for the search. I dislike having to set the match field from match complete area to match any a part of area after I neglect and I’ve already searched utilizing the entire area and can’t discover what I do know have to be there.

I wanted a method to search every area with one click on, so I selected a button to do it.

I’ve a number of fields on which I would like to find a way to search. I didn’t need to write the identical code time and again for every area. If I discover a higher method to code it, then I’ve to recode each occasion of that previous code. Having one process is a lot better.

My button units the main target of the search to the one area to the left of the button after which it calls one process to invoke the discover command. Each such button on the shape units the main target to the sphere at its left and calls the identical, one operate to carry out the search.

Earlier than I get to the code, I want to cowl the idea that it issues the place you set the process. When you have many buttons however just one type, then you possibly can add the process within the code for the shape itself. When you have a couple of type, or if you want to make the process extra normal in case you do want to use it afterward in one other type, then it’s best to add this process to a module and never in your types. I name my module Normal however you may add separate modules with a number of associated procedures so you may simply import them into new databases as you want. This could possibly be your FindRecord module. You discover Modules in the primary database window together with Tables, Queries, Types, Studies, and Macros.

In the event you put your process in your type code, then the scope of your process is legitimate for that type solely. When you have your process in type 1 and also you want to name it in type 2, you’re going to get an error as a result of type 2 can not discover it. In that case, you’ll both have to add one other process to type 2 and preserve two procedures, or higher, put the process into a module in order that each types can discover it and also you solely have to preserve one process.

As soon as you employ a normal module, your code references should even be normal. You can’t use the Me shortcut for a area title as you possibly can in a process inside a type. When a process is inside a type, the code interprets Me to refer to the shape.

In the event you want to refer to a area title in a normal module, you have to use a normal assertion similar to:




(You want to add brackets if the names include areas)

Right here, PurchaseTotal is a area title within the frmInventory type within the Types Access database assortment. If this had been within the frmInventory code, it could simply be:


In our case, we are going to use the Me within the OnClick property within the type to set the main target to one particular area utilizing the Me methodology after which name a process that has no want of referring to a area title, thus bypassing the Me drawback.

This is what to do to create a helpful discover button:

* Make a button utilizing the button device and its wizard.
* Set the button to show textual content and set that textual content to F.
* Title the button cmdFind + Area Title, so to discover on a area referred to as InvNum the title can be cmdFindInvNum.

After the wizard completes, edit the button:

* Set the font dimension to 6, a small however readable dimension.
* Set the tab cease to NO as a result of customers don’t want to cease on the button if they’re tabbing by way of the shape.
* Set the Standing Bar Textual content and the ControlTip Textual content to Find Document in order that customers can simply remind themselves what the button does after they maintain their mouse pointers over your button.

Measurement your button as small as you possibly can and nonetheless find a way to see the F. I exploit 0.1708 inches extensive by 0.166 inches excessive with Arial textual content with my type grid spacing. Your dimension could differ. That is a good dimension as a result of its top is identical as the peak of my textual content and combo packing containers so all of them match togther nicely in every line.

(After you create one button this fashion, you possibly can copy and paste it for the entire remainder of your buttons with all of those settings saved and set within the copy. All you might have to do is to change the title of every button and add the OnClick Occasion Process beneath.)

Now you set the OnClick property to [Event Procedure]. You’re setting the occasion process to act on one particular area. If the sphere title is ProductNumber, then write your occasion process as:



The primary line, the SetFocus motion determines which area your process will search and the Me.Productumber specifies only one area title. In the event you use Display screen.PreviousControl.SetFocus, because the wizard recommends, on your first line, then you’ll search on no matter area you final touched together with your mouse. That is good, if that is what you need, however it isn’t what I would like this button to do.

The second line, FindRecord, calls your customized process. (In Home windows. after you add your customized FindRecord process, you possibly can spotlight FindRecord right here within the type code and proper click on and choose Definition to instantly go to the code.)

Then add your customized process to a module and put it aside:

Public Sub FindRecord()

DoCmd.GotoRecord,, acFirst

SendKeys “%ha%n”, False

DoCmd.RunCommand acCmdFind

Finish Sub

The primary command is non-compulsory so you possibly can remark it out by including a single quote mark in entrance of it if you do not need to use it.

The primary command units the report pointer to the primary report to begin the search. I did this as a result of I believed it greatest to start looking out firstly, however it isn’t obligatory for this process to work.

The second command sends key codes to arrange the discover dialog field. Listed here are some attainable choices from a Microsoft Data Base internet web page [out]

Choose the Match field: %h

Match Any A part of Area: %ha

Match Begin of Area: %hs

Search Solely Present Area (cleared): %e

Match Case (chosen>): %c

Search Fields as Formatted (chosen): %o

Choose the Search field: %r

Search Up: %ru

Search Down: %rd

Choose the Find What field: %n

For instance, SendKeys %h selects the Match field and SendKeys %ha selects the Match field and units the Match field to match any a part of the sphere. You do not have to do each; use a variation of the second assertion. The identical is true for SendKeys %r and SendKeys %ru or SendKeys %rd.

The actual mixture in your process as written right here units the Match field to match any a part of the sphere and it then selects the Find What field for the main target of your cursor. Thus, you might be set to kind in what you might be trying to find. Write your process with the settings that you really want.

The second a part of the SendKeys assertion is an non-compulsory, boolean worth specifying the wait mode. Whether it is set to False (default), management is returned to the process instantly after the keys are despatched. Whether it is set to True, then keystrokes have to be processed earlier than management is returned to your process. Technically we don’t want to specify it as a result of we would like False and the default is False; nevertheless, I like to specify it so it’s clear to me six months from now that’s what I needed.

The % in entrance of every key worth represents the Alt key in Home windows, and I suppose it represents the Command key in Macs. Within the code window, when you spotlight SendKeys within the code and press the F1 operate key; then a assist display screen will come up and clarify normal details about SendKeys. Do not look to Access assist for the particular Find key codes proven above; Access assistance is normal and never all inclusive.

The third command runs the Access Find motion as arrange by you. That is lastly the command that does what you need.

I admit that that is a crude method to do issues, however that is what Access offers us. The SendKeys method is best than the DoMenuItem method however it could have issues in a multi-user atmosphere, as I’ve learn however not skilled.

You may experiment with completely different combos of key codes. You may ship keystrokes on completely different traces or mix them into one line as I’ve finished. I like to recommend putting all of them in onelike as the instance does. In the event you use the %n key code, then put it on the finish as a result of it units the main target to the Find What field and it ought to come final.

Do that out in your Access types and see if that is helpful. I discover it useful as a result of normal customers won’t know to press [control] + f or to use the Edit | Find menu to discover one thing. Each are too nerdy. In the event that they do find out about them, it’s my expertise that they are going to be tripped up sometimes by the default match complete area setting and never understand how to get what they need. Loads relies on coaching and frequency of use. People who find themselves nicely skilled will do higher than poorly skilled customers. Individuals who search sometimes could not bear in mind in addition to frequent customers.

If customers see a button subsequent to the sphere, and when you train them that F means discover, they may in all probability use use it since looking out is so elementary to utilizing a database they may need a easy method to search.

I’ll present you the way to add different helpful type buttons to Access types in different articles.