Solved

search box in access 2003

Posted on 2007-11-27
2
1,247 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

864 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

24 Experts available now in Live!

Get 1:1 Help Now