Subscript out of range when completing more than 1 recipint in CopyTo

I have an editable field (INaddcopy) in a form with type “Names”. Next to it is a button with this formula:

FIELD INaddCopy := @Name([CN];@PickList([Name]:[Shared]));“”

So, the user can select 1 or more names out of the Company’s Name & Address book.

Then, there is a “Submit” button in which an email is sent to the persons in the field INaddcopy:

This script is used:

Dim maildoc As NotesDocument

Dim rtitem As NotesRichTextItem

Dim strPersonName As String

Dim nn As NotesName

Dim recip(5) As String

Set maildoc=New NotesDocument(db)

maildoc.SendTo=doc.INsupv(0)

maildoc.copyTo=doc.INdivmgr(0)

recip(0) = doc.INaddCopy(0)

recip(1) = doc.INaddCopy(1)

maildoc.BlindCopyto = recip

maildoc.Subject = "First notification Injury - " + doc.INNum(0)

Set nn = ss.CreateName(doc.INsupv(0))

strPersonName = nn.Common

Set rtitem = New NotesRichTextItem( mailDoc, “Body” )

'Call rtitem.AppendText("Dear " + doc.INsupv(0) + “,” )

… ETCETERA …

maildoc.Send(0)

The problem is probably in the instruction:

recip(0) = doc.INaddCopy(0)

recip(1) = doc.INaddCopy(1)

maildoc.BlindCopyto = recip

… where I’m getting a “subscript out of range” error

What am I doing wrong?

Subject: subscript out of range when completing more than 1 recipint in CopyTo

If zero or 1 additional copy intos are specified then you cannot refer to doc.InAddCopy(1).

Note that doc.InAddCopy(0) will be valid as set to “” if no copy intos are selected.

Additionally, why is recip being declared as a fixed size array?

If you need to use recip, declare it as a variant.

Dim recip as variant

recip = doc.INAddCopy

mailDoc.BlindCopyTo = recip

If this is the only purpose of recip, skip it and use

mailDoc.BlindCopyTo = doc.INAddCopy

Subject: RE: subscript out of range when completing more than 1 recipint in CopyTo

Hi Andrew,The problem is that when more than 1 addressees are selected in the doc.INaddCopy, the mail is not sent. When there’s only 1 person there’s no problem.

Before I changed to the array thing, my code was this:

Set maildoc=New NotesDocument(db)

maildoc.SendTo=doc.INsupv(0)

maildoc.copyTo=doc.INdivmgr(0)

maildoc.BlindCopyTo=doc.INaddCopy(0)

Also when I left out the (0) it didn’t work.

Subject: RE: subscript out of range when completing more than 1 recipint in CopyTo

Check your InAddCopy variable. Is it marked as allowing multi-values?

Also check your existing document to see what the value of InAddCopy is stores as via Right-click, Document properties.