On Sun, 21 Sep 2003 17:05:42 -0400 in comp.databases.ms-access,
"Saintor" <sa******@REMOVETHIShotmail.com> wrote:
I have a string of email addresses with duplicates. like
"ab*@abc.com; cd*@cde.com; ab*@abc.com"
If I use this string with sendobject, the receiver will get it only once
which is perfect to me. I wonder if it will be the case with other mail
applications than Outlook Express. TIA
(BTW if somebody has code to delete duplicates in a string like this, it
would be appreciated.)
Where did the string come from? If from a table then surely the
duplicates could be filtered out first?
If not then...
The StrTok function below came as an example from Basic MS-PDS 7.1, I
can't remember what the varDummy bit was for (I might have added that
later for some reason, serves me right for not commenting it). You can
use that in the following code that youi'll have to modify to suit
your needs.
Sub DelDupeAddy()
Dim strAddy As String
Dim strTemp As String
Dim strDeDupe As String
strAddy = "ab*@abc.com;
cd*@cde.com;
ab*@abc.com;
x@x.com;
y@y.com;
x@x.com"
' totally enclose each addy with ";" so we don't confuse
'
a@a.com with
aa@a.com later on
strDeDupe = ";"
strTemp = Trim(Strtok(strAddy, ";"))
Do While Len(strTemp)
If InStr(1, strDeDupe, ";" & strTemp & ";") = 0 Then
strDeDupe = strDeDupe & strTemp & ";"
End If
strTemp = Strtok("", ";")
Loop
' strip leading and trailing ; and put spaces back
strDeDupe = Replace(Mid(strDeDupe, 2, Len(strDeDupe) - 2), ";", ";
")
Debug.Print strDeDupe
End Sub
Function Strtok(pstrSrce As Variant, strDelim As String, Optional
varDummy As Variant) As Variant
Static intstart As Integer, strSaveStr As String
Dim intBegPos As Integer, intEndPos As Integer
Dim intLn As Integer
On Error GoTo StrTokError
' If first call, make a copy of the string.
If pstrSrce <> "" Then
intstart = 1: strSaveStr = pstrSrce
End If
intBegPos = intstart
intLn = Len(strSaveStr)
' Look for start of a token (character that isn't delimiter).
Do While intBegPos <= intLn And InStr(strDelim, Mid(strSaveStr,
intBegPos, 1)) <> 0
intBegPos = intBegPos + 1
Loop
' Test for token start found.
If intBegPos > intLn Then
Strtok = ""
Exit Function
End If
' Find the end of the token.
intEndPos = intBegPos
Do While intEndPos <= intLn And InStr(strDelim, Mid(strSaveStr,
intEndPos, 1)) = 0
intEndPos = intEndPos + 1
Loop
Strtok = Trim(Mid(strSaveStr, intBegPos, intEndPos - intBegPos))
If IsNull(pstrSrce) Then
Strtok = Null
End If
' Set starting point for search for next token.
intstart = intEndPos
StrTokExit:
Exit Function
StrTokError:
Resume StrTokExit
End Function
--
A)bort, R)etry, I)nfluence with large hammer.