Solved

search box in access 2003

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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

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

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
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…
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

803 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