Solved

Strip Out Text from Memo Field

Posted on 2014-01-23
8
423 Views
Last Modified: 2014-01-24
I have a Memo field in table that I would like strip out the text between two markers and then write the results to a seperate text field. The first marker is UFMS: and the seceond maker is either single quote or a double quote. In the example below the data that I would like to capture is ---  Obligation Amendment is not processed as Traveller or Travel Site is not active in UFMS Fi   02          0O1PN

I have also attached the db with the table -- Thanks



Example:

Transaction ID: 0O1PNL004               Reference #: 0O1PNL004
` ERROR CODE                                           ERROR DESCRIPTION                                LINE ID         TRN
`             Under review by your agency financial system.
`
`  UFMS:
`             Obligation Amendment is not processed as Traveller or Travel Site is not active in UFMS Fi   02          0O1PNL
`             nancia ...
`             Obligation Amendment is not processed as Traveller or Travel Site is not active in UFMS Fi   03          0O1PNL
`             nancia ...
`             Obligation Amendment is not processed as Traveller or Travel Site is not active in UFMS Fi   04          0O1PNL
`             nancia ...
`             Obligation Amendment is not processed as Traveller or Travel Site is not active in UFMS Fi   05          0O1PNL
`             nancia ...
`
Gov-Trip.accdb
0
Comment
Question by:shieldsco
  • 5
  • 2
8 Comments
 
LVL 84
ID: 39803708
This function would do it:

Function GetData(DataIn As String) As String

    Dim iStart As Integer
    Dim iEnd   As Integer

    iStart = InStr(1, DataIn, "UFMS:")

    If iStart = 0 Then
        GetData = "NODATA"
    Else


        iEnd = InStr(iStart, DataIn, "'")
        If iEnd = 0 Then
            iEnd = InStr(iStart, DataIn, Chr(34))
        End If

        If iStart > 0 And iEnd > 0 Then
            GetData = Mid(DataIn, iStart + 5, iEnd - iStart - 6)
        Else
            GetData = "NODATA"
        End If
    End If

End Function

Open in new window


You'd use it like this:

Dim sDataOut as String
sDataOut=GetData(Me.SomeField)

Note too those are not single quotes, they're known as the "Grave Accent": http://www.theasciicode.com.ar/ascii-printable-characters/grave-accent-ascii-code-96.html
0
 

Author Comment

by:shieldsco
ID: 39803959
When I used the function in a query I get NoData -- Expr1: GetData([Error Category])
0
 

Author Comment

by:shieldsco
ID: 39804091
Can I use the function in a query
0
 
LVL 34

Expert Comment

by:PatHartman
ID: 39804318
Yes you can use the function in a query.

Put a stop in the code and then step through it to see what is being passed in and how it is being evaluated.
0
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.

 

Author Comment

by:shieldsco
ID: 39804380
No luck on running from query -- can you give an example Thanks
0
 

Author Comment

by:shieldsco
ID: 39806343
Can anyone give me an example on how to run the function from a query??
0
 
LVL 84

Accepted Solution

by:
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 500 total points
ID: 39806527
The function works, but as I mentioned the "single quote" is not a single quote, but rather a Chr(96) value (the `  character).

Modify your function to check for that, and then try it again:

Function GetData(DataIn As String) As String

    Dim iStart As Integer
    Dim iEnd   As Integer

    iStart = InStr(1, DataIn, "UFMS:")

    If iStart = 0 Then
        GetData = "NODATA"
    Else


        iEnd = InStr(iStart, DataIn, "'")
        If iEnd = 0 Then
            iEnd = InStr(iStart, DataIn, Chr(96))
        End If

        If iStart > 0 And iEnd > 0 Then
            GetData = Mid(DataIn, iStart + 5, iEnd - iStart - 6)
        Else
            GetData = "NODATA"
        End If
    End If

End Function

Open in new window

Note the change on Line 15 from Chr(34) to Chr(96).

Also, the FIRST instance of ` after your starting marker is just a few characters downstream. If your data is always in this format - that is, if the first marker is always "UFMS:" and the second marker is the SECOND instance of `, then you'll have to modify your function like this:

Function GetData(DataIn As String) As String

    Dim iStart As Integer
    Dim iEnd   As Integer

    iStart = InStr(1, DataIn, "UFMS:")

    If iStart = 0 Then
        GetData = "NODATA"
    Else
        '/ get the first instance of Chr(96)
        iEnd = InStr(iStart, DataIn, Chr(96))
        '/ get the second intance of Chr(96)
        iEnd = InStr(iEnd + 1, DataIn, Chr(96))

        If iStart > 0 And iEnd > 0 Then
            GetData = Mid(DataIn, iStart + 5, iEnd - iStart - 6)
        Else
            GetData = "NODATA"
        End If
    End If

End Function

Open in new window


Now you should be able to use the function in your query
0
 

Author Closing Comment

by:shieldsco
ID: 39806581
works well -- Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In the article entitled Working with Objects – Part 1 (http://www.experts-exchange.com/Microsoft/Development/MS_Access/A_4942-Working-with-Objects-Part-1.html), you learned the basics of working with objects, properties, methods, and events. In Work…
Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
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…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

867 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

20 Experts available now in Live!

Get 1:1 Help Now