Solved

How extract string of characters to the right of the 1st hyphen

Posted on 2016-09-13
4
31 Views
Last Modified: 2016-09-13
If I have a string of characters that looks like this:

#10 Small - something - something else

And I want to extract in query designer this part of it: (everything to the right of the 1st hyphen not including the space in front of the 1st "something")

something - something else

How can I do this?
0
Comment
Question by:SteveL13
  • 2
4 Comments
 
LVL 84
ID: 41796531
Use a combination of Mid and Instr.

What have you tried so far?
0
 

Author Comment

by:SteveL13
ID: 41796536
Right([tblPaper.Description],InStr([tblPaper.Description],"-")-2)

But it isn't even close.
0
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 250 total points
ID: 41796554
Mid([tblPaper.Description], InStr([tblPaper.Description], "-") + 2, Len([tblPaper.Description]) - InStr([tblPaper.Description], "-"))
0
 
LVL 19

Assisted Solution

by:crystal (strive4peace) - Microsoft MVP, Access
crystal (strive4peace) - Microsoft MVP, Access earned 250 total points
ID: 41796569
in case there may not be a space after the first hyphen, here is a slight modification to what Scott wrote to TRIM instead:
trim(Mid([tblPaper.Description], InStr([tblPaper.Description], "-") +1 ))

Open in new window

also, the 3rd argument, how many characters to get, is optional so I left it out

if you are doing this in a query, create another column to filter for only records having a dash:

field: Description
table: tblPaper
criteria: Like "*-*"

btw, Description is a reserved word

http://allenbrowne.com/AppIssueBadWord.html
0

Featured Post

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Describes a method of obtaining an object variable to an already running instance of Microsoft Access so that it can be controlled via automation.
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…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.

919 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now