Error 87 When Creating Large Email Distribution List

D

DoveArrow

I'm running the following code to try and create an email distribution
list. While this code works fine for small distribution lists, for
long distribution lists I'm getting an "Error 87: Unexpected Error"
message.

Now I've been doing some research, and while I'm not entirely sure
about this, it sounds like you can't pass a string using the hyperlink
function if it's longer than 255 characters. If that's my problem, is
there another solution to my dilemma, or a way to work around it? If
that's not my problem, what exactly is happening here, and how can I
correct it? Let me know. Thanks.

Private Sub EmailAdvisors_Click()
Dim rs As DAO.Recordset
Dim strCriteria As String

On Error GoTo Err_EmailAdvisors_Click

Set rs = Me.RecordsetClone 'Create recordset based on current form.
rs.MoveFirst 'Move to first record in recordset.

Do While Not rs.EOF 'Perform the following sequence until it reaches
the bottom of the recordset.
strCriteria = strCriteria & "; " & rs! 'Add email address
and semicolon to strCriteria.
rs.MoveNext 'Move to next record in recordset.
Loop 'Repeat for each record in recordset.

strCriteria = Right(strCriteria, Len(strCriteria) - 1) 'Remove extra
semicolon.

FollowHyperlink "mailto:" & strCriteria 'Open new email in Microsoft
Outlook.

Exit_EmailAdvisors_Click:
rs.Close 'Close recordset.
Set rs = Nothing 'Reset recordset to nothing.
Exit Sub

Err_EmailAdvisors_Click:
MsgBox "Error " & Err.Number & ": " & Err.Description
GoTo Exit_EmailAdvisors_Click
End Sub
 
D

DoveArrow

I think I found a solution. I replaced the following line of code

FollowHyperlink "mailto:" & strCriteria

with this

DoCmd.SendObject , , , strCriteria

Now it seems to work no matter how long my string is.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top