?
Solved

search box in access 2003

Posted on 2007-11-27
2
Medium Priority
?
1,263 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 1500 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

NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

Question has a verified solution.

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

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…
Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Suggested Courses

777 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