Solved

Extract characters in access

Posted on 2011-03-02
7
425 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
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 250 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

Industry Leaders: 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!

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…

622 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