Jack said:
Dirk,
Thank you so much for the quick reply.
Unfortunately, I couldn't reply to this one as quickly.
I am trying to import emails
into exchange. The bodys consists of frontpage forms. I am trying to
extract that data into access database - each field from form is
extracted. My code looks for 'keyword' AND a vbcr or a chr(13) - any
data between is trim and inserted in database. As I mentioned before
the SINGLE fields (first_name,last_name, etc)extract fine. The
problem is that for some unknown reason Frontpage's form processor
moves any memoboxes to the end of the email. HERE is the kicker - Not
only do they move it to the end, but it also inserts (2) vbcrlf
between the last single field(next field)AND (2) vbcrlf at the START
of data for that field. It gets real ugly if user uses memobox to
write a book or worse writes a book in one but leaves the other
memofield empty.
My database is ready to go EXCEPT these dreaded memo fields. Any help
would be so ever greatful!!!
Here is my email sample:
first_name: jack
last_name: bright
memofield1:
here is start of data
it may continue and
continue
memofield2:
memofield3:
notice field2 no data
still has the (2)vbcrlf between
I was thinking I could replace all of the vbcrlf at the start where
memofields begin and replace with "" then do another to insert one
right before memofield begins - that way data will extract fine.
here is code I use to extract:
firstname = ExtractDetail(rstExchange!Body, "firstname:")
memofield1 = ExtractDetail(rstExchange!Body, "memofield1:" & vbCrLf &
vbCrLf) **notice the vbcrlf & vbcrlf - this DOES extract the first
line of text / or until it hits a chr(13) within the body of
memofield.
____________________ here is function to extract
Public Function ExtractDetail(textLine As Variant, FormItemReq As
String) As Variant
Dim StartLine As Variant, EndLine As Variant, ExtractText As Variant
StartLine = InStr(textLine, FormItemReq)
If StartLine > 0 Then
StartLine = StartLine + Len(FormItemReq)
EndLine = InStr(StartLine, textLine, vbCrLf)
ExtractText = Mid(textLine, StartLine, EndLine - StartLine)
End If
If Len(ExtractText) = 0 Then ExtractText = ""
ExtractDetail = Trim(ExtractText)
End Function
I have been struggling for weeks on this. I have asked numerious and
have yet to find a solution to this. If I going about this the wrong
way or if you can suggest a better way I would be really happy!
Here is a modified version of the function that you may serve. The
trouble is that the input data isn't entirely regular.
'------ start of code ------
Public Function ExtractDetail( _
textLine As Variant, _
FormItemReq As String, _
Optional Dlm As String = vbCrLf) _
As Variant
Dim StartLine As Long, EndLine As Long, ExtractText As String
StartLine = InStr(textLine, FormItemReq)
If StartLine > 0 Then
StartLine = StartLine + Len(FormItemReq)
EndLine = InStr(StartLine, textLine, Dlm)
ExtractText = Mid(textLine, StartLine, EndLine - StartLine)
While Left(ExtractText, 2) = vbCrLf
ExtractText = Mid(ExtractText, 3)
Wend
End If
ExtractDetail = Trim(ExtractText)
End Function
'------ end of code ------
Note the additional, optional argument "Dlm". You need to specify this
differently for the memo fields. This is how I tested:
strFirstName = ExtractDetail(strEmail, "first_name:")
strLastName = ExtractDetail(strEmail, "last_name:")
strMemo1 = ExtractDetail(strEmail, _
vbCrLf & "memofield1:" & vbCrLf, _
vbCrLf & vbCrLf)
strMemo1 = ExtractDetail(strEmail, _
vbCrLf & "memofield2:" & vbCrLf, _
vbCrLf & vbCrLf)
strMemo1 = ExtractDetail(strEmail, _
vbCrLf & "memofield3:" & vbCrLf, _
vbCrLf & vbCrLf)