[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

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

Posted on 2017-05-17
4
Medium Priority
?
75 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 31

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 39

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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
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…

650 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