Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Extract characters in access

Posted on 2011-03-02
7
Medium Priority
?
429 Views
Last Modified: 2012-05-11
I need to extract the following in a field:

high cost
or
hc
or
highcost

in the same field in an access 2000
0
Comment
Question by:bar0822
[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
  • 3
  • 3
7 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 35017433
No idea what you are trying to do.
Please post an example.
0
 
LVL 11

Expert Comment

by:LambertHeenan
ID: 35017455
Well you don't say where you need to do this: in a query, on a form or report?

But here is a function that will return these strings given the filed value as an input

Function isHighCost(strFieldValue as String) as String
dim StrResult as String

      If Instr(strFieldValue,"high cost") > 0 then
            StrResult = "high cost"
      ElseIf Instr(strFieldValue," hc ") > 0 then ' note the spaces to eliminate some false matches
            StrResult = "hc"
      ElseIf Instr(strFieldValue,"highcost") > 0 then
            StrResult = "highcost"
      Else
            StrResult = "" , Signal that the text was not found
      End If
      isHighCost = StrResult
End Function
0
 

Author Comment

by:bar0822
ID: 35020633
I need to parse a column for any word that includes either HC or High Cost but not HC Split and insert into another column.
There are other words (characters) before and sometimes after.
here is an example of some data:
Allow HC
Allow HC TX
Do not allow High Cost
High Cost
HC
Allow High Cost Split (do not want this one)
Sorry - the sample function above worked but realized that was not what I was looking for due to improper question explanation.  
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 11

Expert Comment

by:LambertHeenan
ID: 35021933
OK. That would just require a slight modification...

Function isHighCost(strFieldValue as String) as String
dim StrResult as String

      If Instr(strFieldValue,"high cost") > 0 then
                  If Instr(strFieldValue,"split") = 0 then ' "Split" NOT found in string
                        StrResult = "high cost"
                  End If
      ElseIf Instr(strFieldValue," hc ") > 0 then ' note the spaces to eliminate some false matches
            StrResult = "hc"
      ElseIf Instr(strFieldValue,"highcost") > 0 then
            StrResult = "highcost"
      Else
            StrResult = "" , Signal that the text was not found
      End If
      isHighCost = StrResult
End Function
0
 
LVL 11

Accepted Solution

by:
LambertHeenan earned 1000 total points
ID: 35022014
Or, if in every instance you want to exclude 'split', i.e.

hc split
high cost split
highcost split

would all be exluded, then the code would be

Function isHighCost(strFieldValue as String) as String
dim StrResult as String

        
strResult = "" ' Default return value
If Instr(strFieldValue,"split") = 0 then ' "Split" NOT found in string
      If Instr(strFieldValue,"high cost") > 0 then
             StrResult = "high cost"
        ElseIf Instr(strFieldValue," hc ") > 0 then ' note the spaces to eliminate some false matches
              StrResult = "hc"
        ElseIf Instr(strFieldValue,"highcost") > 0 then
              StrResult = "highcost"
        End If
End If
isHighCost = StrResult
End Function
0
 

Author Comment

by:bar0822
ID: 35114025
thanks but the function does not work - I am not getting any records. I copied your function in a module  and called it modHighCost and used in query as Program: isHighCost([HCProg]) and when I run the query I am getting a column of empty strings.  Those values are in the column so not sure what is wrong.
0
 

Author Closing Comment

by:bar0822
ID: 35115866
The solution was accurate and easy to follow and reuse as needed.  thanx
0

Featured Post

What Is Blockchain Technology?

Blockchain is a technology that underpins the success of Bitcoin and other digital currencies, but it has uses far beyond finance. Learn how blockchain works and why it is proving disruptive to other areas of IT.

Question has a verified solution.

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

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…
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…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

722 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