Solved

Extract characters in access

Posted on 2011-03-02
7
417 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

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.

Question has a verified solution.

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

It took me quite some time to sort out all the different properties of combo and list boxes available from Visual Basic at run-time. Not that the documentation is lacking: the help pages are quite thorough and well written. The problem was rather wh…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

910 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

21 Experts available now in Live!

Get 1:1 Help Now