Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Import text by keywords 2

Status
Not open for further replies.

btj

Technical User
Nov 17, 2001
94
US
I am trying to create some code that will copy text based upon a starting and ending keyword.

For example, I would want the code to begin copying everything when it sees "Description" but stop when it sees "end."

The amount of data copied will be different for each document.

I am messing around with a complex If...Then statement but it hasn't worked yet.

I really appreciate any advice.

- Ben
 
Well... you can use the function InStrRev (which I wrote, since Access doesn't have it) to get the last space, and have something like:

Trim(Mid(strData,InStr(strData," ")))
Trim(Left(strData,InStrRev(strData," ")))

Here is the InStrRev function:
Code:
Public Function InStrRev(strInput As String, strTarget As String) As Integer
    Dim X As Integer
    
    For X = Len(strInput) To 1 Step -1
        If Mid(strInput, X, 1) = strTarget Then
            InStrRev = X
            Exit Function
        End If
    Next 'x
End Function
(if anyone comes up with a better way.. let me know...)

Hope This Helps...

GComyn
 
Ben,

To not copy the ending keyword, simply swap a couple of code segments. For example, instead of this:
Code:
     If Left(strData, 10) = "Technique:" Then
       boolCopy1 = True
       'rs.AddNew
     End If
     If boolCopy1 Then
       strCopy1 = strCopy1 & strData & " "
       rs!ProductRequirement = strCopy1
       'rs.Update
     End If
     If Left(strData, 20) = "Completion Criteria:" Then
       boolCopy1 = False
     End If
put this:
Code:
     If Left(strData, 10) = "Technique:" Then
       boolCopy1 = True
       'rs.AddNew
     End If
     If Left(strData, 20) = "Completion Criteria:" Then
       boolCopy1 = False
     End If
     If boolCopy1 Then
       strCopy1 = strCopy1 & strData & " "
       rs!ProductRequirement = strCopy1
       'rs.Update
     End If
This will "turn off" copying when the ending keyword is reached before it has a chance to copy the keyword itself.

--Ryan
 
Ryan,
That was it...thanks so much. It worked fabulously.

I cannot thank you enough for all of your help.

- Ben
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top