Name searching problem

D

David G.

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.

Any thoughts would be greatly appreciated.
THANKS!
David G.
 
J

John W. Vinson

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.
 
D

David G.

Thanks! Works perfect.

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 thebound
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 queryas
the combo's rowsource.
THANKS!
David G.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top