Solved

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

Posted on 2006-07-13
6
462 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Top 1 of each supplier 55 56
Access query expression 6 21
aggregate query? 20 50
MS Access Delete All Excel sheets 1 9
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
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…
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…

773 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