Solved

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

Posted on 2017-05-17
4
36 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 34

Accepted Solution

by:
ste5an earned 250 total points
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
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 37

Assisted Solution

by:PatHartman
PatHartman earned 125 total points
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 47

Assisted Solution

by:Dale Fye (Access MVP)
Dale Fye (Access MVP) earned 125 total points
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Join & Write a Comment

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

739 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