Hi, I've written some code that sends an e-mail to a number of recipients from a recordset. The recordset varies in number and I got some advice on here that I needed to Redim the recipient array so that it could house the right number of addresses each time the code is run.
The code i've got that surrounds the array is:
Set ToRecRst = dbs.OpenRecordset("SELECT tbl_IndividualRecipients.[E-Mail] FROM tbl_IndividualRecipients;")
ToRecRst.MoveLast
ToRecRst.MoveFirst
i = ToRecRst.RecordCount - 1
ReDim strRecTo(i, 0)
n = 1
While Not ToRecRst.EOF
strRecTo(n, 0) = ToRecRst.[E-Mail]
n = n + 1
ToRecRst.MoveNext
Wend
This works in part but it only sends an e-mail to the first person in the list not everyone. Also if there is only one person in the recipient list it fails- i'm assuming it doens't like assigning an array (0,0)
I thought i'd fixed the problem by setting i as follows:
If ToRecRst.RecordCount > 1 Then
i = ToRecRst.RecordCount -1 '## to allow for 0 being 1st array pos
Else:
i = ToRecRst.RecordCount
End If
and that works for single recipients but still only sends the e-mail to the first person if there is more than one recipient in the recordset.
Sorry this is a bit specific but this is the first time i've really come across arrays and i'm finding my feet to say the least, thanks, Tom.
The code i've got that surrounds the array is:
Set ToRecRst = dbs.OpenRecordset("SELECT tbl_IndividualRecipients.[E-Mail] FROM tbl_IndividualRecipients;")
ToRecRst.MoveLast
ToRecRst.MoveFirst
i = ToRecRst.RecordCount - 1
ReDim strRecTo(i, 0)
n = 1
While Not ToRecRst.EOF
strRecTo(n, 0) = ToRecRst.[E-Mail]
n = n + 1
ToRecRst.MoveNext
Wend
This works in part but it only sends an e-mail to the first person in the list not everyone. Also if there is only one person in the recipient list it fails- i'm assuming it doens't like assigning an array (0,0)
I thought i'd fixed the problem by setting i as follows:
If ToRecRst.RecordCount > 1 Then
i = ToRecRst.RecordCount -1 '## to allow for 0 being 1st array pos
Else:
i = ToRecRst.RecordCount
End If
and that works for single recipients but still only sends the e-mail to the first person if there is more than one recipient in the recordset.
Sorry this is a bit specific but this is the first time i've really come across arrays and i'm finding my feet to say the least, thanks, Tom.