Solved

search box in access 2003

Posted on 2007-11-27
2
1,244 Views
Last Modified: 2012-08-13
my main table has firstname, lastname, medicalnumber, ...
on my form view, i have all these fields plus whatever fields of additional subforms. i would like to create a textbox and a command button where user can enter either firstname, lastname or medicalnumber and search for record that matches either one of these fields.

does it how you normally do? another way is to have additional combo box where user can select first name or last name or medical number and then search. would this be more efficient? please advise
0
Comment
Question by:cuc888
2 Comments
 
LVL 1

Expert Comment

by:pmn4004
ID: 20364428
hi,
when you want to add search box you have to add three textbox in order to use each of them for searching one of the mentioned fields. if you want to add one text box you have to select in which field you want to search. the easiest way is to add three combo box by wizard.
0
 
LVL 3

Accepted Solution

by:
Garbi4332 earned 500 total points
ID: 20365357
I would generally create a query as the data source for the form.  The query's WHERE clause can compare search text to ([LastName] LIKE ("%" + [Form]![FormName]![SearchTextBoxName] + "%")) OR ([FirstName] LIKE ("%" + [Form]![FormName]![SearchTextBoxName] + "%")) OR ([MedicalNumber] LIKE ("%" + [Form]![FormName]![SearchTextBoxName] + "%")).  If nothing is entered in the search text box, this should return all records (the exact syntax might be slightly different than what I just listed depending on whether your tables are in Access or in SQL Server).  Simply have the search button's Click event do a Me.Requery.

This may return multiple records, of course, depending on the search criteria.

Also, you could use a parameterized query (or preferably a Stored Procedure if you are working with an .adp project with a SQL back-end) and simply enter [Form]![FormName]![SearchTextBoxName] in the Input Parameters property of the form's property dialog box (on the Data tab).  The query (in Access) would look something like this:

PARAMETERS [@SearchText] Text (255);
SELECT
  *
FROM
  TableWhatever
WHERE
  (LastName LIKE ("*" + [@SearchText] + "*")) OR
  (FirstName LIKE ("*" + [@SearchText] + "*")) OR
  (MedicalNumber LIKE ("*" + [@SearchText] + "*"))

I'm assuming that MedicalNumber is a text-based field.  If it's a number field, we might have to make a slight adjustment to that last line.  The square brackets are important - don't leave them out.  Access uses asterisks (*) as it's wildcard character.  If you're using a SQL Stored Procedure, the query (minus the PARAMETERS clause at the beginning) is the same but use percentage symbols (%) as wildcards instead.
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
Today's users almost expect this to happen in all search boxes. After all, if their favourite search engine juggles with tens of thousand keywords while they type, and suggests matching phrases on the fly, why shouldn't they expect the same from you…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now