Text Box to show last name only

  • Thread starter Thread starter Gary Hull
  • Start date Start date
G

Gary Hull

I have a field in a table where I enter peoples names (Hull, Gary) the
field is bound to a text box on a form, what I need to do is be is to have
the text box on the field to show the Last name only.

Thanks for your help
 
Use Instr() to locate the comma in the field.
Use Left() to pull out the previous characters.
Use IIf() to test if there is a surname.

The Control Source of the text box will be something like this:
=IIf(Instr([FullName],",")>1,Left([FullName],Instr([FullName],",")-1),False)
 
You have discovered a "rule" of good database design. You should have
separate fields for the first name and last name (and middle name/initial).
You can then combine them in any way you need in queries e.g. [LastName] & ",
" & [FirstName] & " " & [MiddleInitial].
 
How would I go about getting the first name?

If I understand INSTR I would have to start from end of the string and work
back. Not sure how to do that since I won’t know how long each string is.
 
Use:
- Len() to get the length of the field,
- Instr() to locate the comma,
- Mid() to read the rest of the field,
- Trim() to dump the leading space(s).

Note that you can omit the last argument with Mid(), and it picks up the
rest of the string from the n-th character.
 

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

Back
Top