Solved

Extract characters in access

Posted on 2011-03-02
7
412 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 
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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

746 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

10 Experts available now in Live!

Get 1:1 Help Now