View Single Post
  #2  
Old May 28th, 2010, 02:07 AM posted to microsoft.public.access
John W. Vinson
external usenet poster
 
Posts: 18,261
Default Name searching problem

On Thu, 27 May 2010 19:17:42 -0400, David G. wrote:

I have an interesting request from a user, but I don't see how to
implement the request.
When populating a combox with employee names, the user wants to see
first & last names which match any text being typed in.
Example, if the user types in "LA", the drop down box would include:
"Larry Johnson"
"Larimy Smith"
"Lansdown, Phil"
"Lany, Tom"

I feel like I will need to create a table with 2 entries for each
name. The first entry would be [First] & " " & [Last], and the second
entry [Last] & ", " & [First]. The problem is keeping the table
current with any name changes without rebuilding the table every time
there is a name change.


You're missing the most powerful feature of Access: Queries.

You certainly do NOT need to, nor should you, have the full name stored in any
table, in either format!

Your employee table should have fields such as EmployeeID (a unique, stable,
primary key), LastName, and FirstName.

You can base two combo boxes on two queries based on this table, using your
expressions as calculated fields in the query, and the EmployeeID as the bound
column. These queries will dynamically retrieve whatever names are currently
in the table - that's what queries are *for*. Nothing is needed to "keep the
table current" or "rebuild".

You could even include every name in the combo's rowsource twice, once each
way, using a UNION query. Given the above table design, you can go to the SQL
window of a new query and edit it to

SELECT EmployeeID, [LastName] & ", " & [Firstname] FROM Employees
UNION ALL
SELECT EmployeeID, [FIrstName] & " " & [Lastname] FROM Employees
ORDER BY 2;

The 2 means to order by the second field (the full name). Use this query as
the combo's rowsource.

--

John W. Vinson [MVP]