?
Solved

Create two calculated fields in a table based on one field entered

Posted on 2017-05-17
4
Medium Priority
?
63 Views
Last Modified: 2017-05-18
I have a table with a field named "Name".  If I enter John Doe in the field I want two calculated fields in the table to populate.  One being "FirstName" and the result of the calculation would be "John".  The other calculated field would be "LastName" and the result would be "Doe".

I've tried these expressions in the FirstName calculated field but get an error.  (all characters up to the first space)

Left([Name],(InStr(1,[Name]," "))-1)
and
Left(Name, Instr(1, Name, " ") - 1)
and
Left(Name,Instr(Name," ")-1)

But then also, what would be the proper expression for the LastName?

But I also think I need to trim any leading spaces before and after "John Doe" in the event one was typed, correct?
0
Comment
Question by:SteveL13
[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
4 Comments
 
LVL 35

Accepted Solution

by:
ste5an earned 1000 total points
ID: 42139497
To keep this short: Don't try it. There are for example double names without hyphen. Names which are entered in the wrong order. You will get for sure wrong names.

I would create two new normal columns and update them once. Then the users need to clean up the values. Depending on the context, this could be feáture in your input UI, but not in the table itself.

To parse use: Mid([FullName],1,InStr([FullName]," ")-1)  and Mid([FullName],InStr([FullName]," ")+1). But you need to add an IIF to test whether a space is in your column to avoid errors.
0
 
LVL 30

Expert Comment

by:hnasr
ID: 42139535
try for a field name t:
trim(left(trim(t), instr(trim(t)," ")-1))
trim(right(trim(t),len(trim(t))-instr(trim(t)," " )))
0
 
LVL 38

Assisted Solution

by:PatHartman
PatHartman earned 500 total points
ID: 42139617
Once you use a reserved word or a name with embedded spaces or special characters you ALWAYS have to enclose the offending name in square brackets.

FirstName:Left([Name],Instr([Name]," ")-1)
LastName:Mid([Name], Instr([Name], " ") +1)
0
 
LVL 48

Assisted Solution

by:Dale Fye
Dale Fye earned 500 total points
ID: 42140198
I agree with Ste5an, your best bet is to go with a single field for Firstname and another field for LastName on your form.  Why do you think most web applications ask for these two pieces of data separately, it is because it is difficult to separate them properly, because you never know what someone will enter when given a Name field.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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…
Microsoft Access is a place to store data within tables and represent this stored data using multiple database objects such as in form of macros, forms, reports, etc. After a MS Access database is created there is need to improve the performance and…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
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