Solved

search box in access 2003

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

Suggested Solutions

Title # Comments Views Activity
How to prevent deleting SQL tables thru FE Application? 20 85
How can I have an Calculator icon for a button? 36 62
Dinamic report to Crosstab query 9 33
ADODB problem 20 37
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

839 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