How to search for vbCRLF within a string

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have a memo field with multiple sentences in it. I'm trying to pull out
just the second sentence to autopopulate another field. Each sentence is
seperated by 2 vbCRLFs. How can I pull out just the second sentence?

My thought was to locate the 2nd vbcrlf from the left and also from the
right then store what was in the middle. But I can't even locate the first
vbcrlf. This is what I've tried so far with no luck.

lngVBCRLF1Loc=instr(vbcrlf,me.prodprocedures)
or
lngVBCRLF1Loc=instr((Chr13)+chr(10)),me.prodprocedures)

I get a 0 every time.

Please help
 
In
MWG said:
I have a memo field with multiple sentences in it. I'm trying to
pull out just the second sentence to autopopulate another field.
Each sentence is seperated by 2 vbCRLFs. How can I pull out just the
second sentence?

My thought was to locate the 2nd vbcrlf from the left and also from
the right then store what was in the middle. But I can't even locate
the first vbcrlf. This is what I've tried so far with no luck.

lngVBCRLF1Loc=instr(vbcrlf,me.prodprocedures)
or
lngVBCRLF1Loc=instr((Chr13)+chr(10)),me.prodprocedures)

I get a 0 every time.

Please help

You've got the arguments in the wrong order. The string to be searched
goes before the string you're searching for. Try this:

lngVBCRLF1Loc=InStr(Me.prodprocedures, vbCrLf)

Or maybe, if the sentences are always separated by *two* CRLFs in a row,
you should use this:

lngVBCRLF1Loc=InStr(Me.prodprocedures, vbCrLf & vbCrLf)
 
Dirk Goldgar said:
In

You've got the arguments in the wrong order. The string to be searched
goes before the string you're searching for. Try this:

lngVBCRLF1Loc=InStr(Me.prodprocedures, vbCrLf)

Or maybe, if the sentences are always separated by *two* CRLFs in a row,
you should use this:

lngVBCRLF1Loc=InStr(Me.prodprocedures, vbCrLf & vbCrLf)

If all that's wanted is the second sentence, there's really no need to use
the InStr function: the Split function's what you want:

To get the second sentence, you'd use

Split(Me.prodprocedures, vbCrLf & vbCrLf)(1)
 
In
Douglas J. Steele said:
If all that's wanted is the second sentence, there's really no need
to use the InStr function: the Split function's what you want:

To get the second sentence, you'd use

Split(Me.prodprocedures, vbCrLf & vbCrLf)(1)

Yes, but that will give an error if there is no second sentence.
 
The split will work fine for now. At the moment, every record will have at
least 2 sentences. But at least I know what to look for when "never has less
than 2 sentences" becomes "Oh, I forgot about that situation".

Thanks so much for the help!
 
If InStr(Me.prodprocedures, vbCrLf & vbCrLf) > 0 Then
strSecondSentence = Split(Me.prodprocedures, vbCrLf & vbCrLf)(1)
Else
strSecondSentence = "Only one sentence given.
End If
 
Douglas J. Steele said:
If InStr(Me.prodprocedures, vbCrLf & vbCrLf) > 0 Then
strSecondSentence = Split(Me.prodprocedures, vbCrLf & vbCrLf)(1)
Else
strSecondSentence = "Only one sentence given.
End If

Or...., the magical cure all fix everything approach:

on error resume next


;-)
 
Back
Top