Solved

MS Access -- Left() and InStr() Problem

Posted on 2006-07-13
6
464 Views
Last Modified: 2008-07-03
Here is my issue:

I am using the following in select statement:

Left(N.FirstName,InStr(1,N.FirstName,' '))

It works fine when N.FirstName is two words but return nothing when it is only one word.

I understand because InStr(1,N.FirstName,' ') is returning '0' then I am tryng to get everything to the left of '0'.  Is there away to put in some sort of if statement to take this into account.

0
Comment
Question by:daugh016
  • 2
  • 2
  • 2
6 Comments
 
LVL 65

Expert Comment

by:rockiroads
ID: 17100393
U have to make use of IIF

assuming this is done in a query

Left(N.FirstName,   IIF(InStr(1,N.FirstName,' ')>0,InStr(1,N.FirstName,' '),Len(N.FirstName))

0
 
LVL 65

Expert Comment

by:rockiroads
ID: 17100399
ok, my mistake. Out of practice I give the answer but dont always give an explanation. Sorry about this, I hadnt realise what I do was considered Post Tagging
So if u need an explanation, let me know
0
 
LVL 4

Expert Comment

by:Carl2002
ID: 17100406
It is returning nothing when N.Firstname is one word because of the " " at the end of the statement. The expression is specifically searching for the first space, if there isn't one it will fall down.

Can you explain a little more what you are trying to achieve?
0
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 

Author Comment

by:daugh016
ID: 17100439
Carl,

If someones first name is two words, I just want the first one.  

Example if someones name is Mike, I want it to show Mike.
Example if someones name is John Mark, I want it to show John.

Rockiroads,

I couldn't get it to work.  It says missing operator.

0
 
LVL 4

Accepted Solution

by:
Carl2002 earned 50 total points
ID: 17100498
Try this

Expr1: IIf(InStr([field1]," ")=0,[field1],Left([field1],InStr([field1]," ")))
0
 

Author Comment

by:daugh016
ID: 17100541
Thanks Carl.  That worked
0

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
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…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

827 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