Solved

Extract characters in access

Posted on 2011-03-02
7
419 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
  • 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
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.

 
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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

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.
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…
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