R
Rich Locus
Hello Access Group:
I'm trying to find a faster way to eliminate non-printable characters from a
memo field. I have an Access application that reads email from Outlook and
for certain messages saves the text of the message into a table in a Memo
field. The issue is that so many emails have embedded characters that if
copied straight to the memo field show up as black rectangles
(non-printable). It's not pretty sight when trying to read through the
jumble of black boxes.
So I was able to write a routine that loops through every character of the
email text and eliminates the non-printables by copying only valid characters
(character-by-character) to a variant data type, then when finished, copying
the variant to the table's memo field.
Here's a snippet of code
' ************************************************************
' Microsoft Access Code After Reading an Outlook Email Message
' ************************************************************
Dim varCleanBody As Variant
Dim i As Long
Dim intConvertedToOctal As Integer
' Note - EmailText is Defined As a Memo Field in a Table
' ****************************************************
' Scan Through Each Character Of An Email Message
' And Eliminate Non-Printing Characters
' (Keep CR/LF which is Octal 12 and 15)
' By Only Moving Printable Characters To varCleanBody
' Then moves the filtered results from varCleanBody
' to Table Field "EmailText" Which is Defined as Memo
' ****************************************************
varCleanBody = ""
For i = 1 To Len(Mailobject.Body)
intConvertedToOctal = Oct(Asc(Mid(Mailobject.Body, i, 1)))
If (intConvertedToOctal = 12 Or intConvertedToOctal = 15 Or _
intConvertedToOctal > 37) Then
varCleanBody = varCleanBody & Mid(Mailobject.Body, i, 1)
End If
Next i
recOut!EmailText = varCleanBody
This code works but it takes an extremely long time to run.
I'm trying to find a faster way to eliminate non-printable characters from a
memo field. I have an Access application that reads email from Outlook and
for certain messages saves the text of the message into a table in a Memo
field. The issue is that so many emails have embedded characters that if
copied straight to the memo field show up as black rectangles
(non-printable). It's not pretty sight when trying to read through the
jumble of black boxes.
So I was able to write a routine that loops through every character of the
email text and eliminates the non-printables by copying only valid characters
(character-by-character) to a variant data type, then when finished, copying
the variant to the table's memo field.
Here's a snippet of code
' ************************************************************
' Microsoft Access Code After Reading an Outlook Email Message
' ************************************************************
Dim varCleanBody As Variant
Dim i As Long
Dim intConvertedToOctal As Integer
' Note - EmailText is Defined As a Memo Field in a Table
' ****************************************************
' Scan Through Each Character Of An Email Message
' And Eliminate Non-Printing Characters
' (Keep CR/LF which is Octal 12 and 15)
' By Only Moving Printable Characters To varCleanBody
' Then moves the filtered results from varCleanBody
' to Table Field "EmailText" Which is Defined as Memo
' ****************************************************
varCleanBody = ""
For i = 1 To Len(Mailobject.Body)
intConvertedToOctal = Oct(Asc(Mid(Mailobject.Body, i, 1)))
If (intConvertedToOctal = 12 Or intConvertedToOctal = 15 Or _
intConvertedToOctal > 37) Then
varCleanBody = varCleanBody & Mid(Mailobject.Body, i, 1)
End If
Next i
recOut!EmailText = varCleanBody
This code works but it takes an extremely long time to run.