Help with Dim As Varient

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am using the following code snipit to send an email from Access to
recipients listed in the following form controls. Everything works great
except that if I don't have all 4 controls populated with a name, I get an
error message. Is there a way I can re-write this a bit in case someone only
wants to email to 2 people and need to leave 2 of the fields on the form
blank? Thank you.

(part of the code)
Dim recip(5) As Variant
recip(0) = (Me.EmailCC1)
recip(1) = (Me.[EmailCC2])
recip(2) = (Me.[EmailCC3])
recip(3) = (Me.[EmailCC4])

doc.COPYTo = recip
 
Dim recip(5) As Variant
recip(0) = (Me.EmailCC1)
recip(1) = (Me.[EmailCC2])
recip(2) = (Me.[EmailCC3])
recip(3) = (Me.[EmailCC4])
ReDim Preserve recip(3)
 
Thanks Douglas. When I add ReDim Preserve Recip(3) I get a message: "Array
Already Dimensioned". Do you know why? Thanks.

Douglas J Steele said:
Dim recip(5) As Variant
recip(0) = (Me.EmailCC1)
recip(1) = (Me.[EmailCC2])
recip(2) = (Me.[EmailCC3])
recip(3) = (Me.[EmailCC4])
ReDim Preserve recip(3)


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


Alex said:
I am using the following code snipit to send an email from Access to
recipients listed in the following form controls. Everything works great
except that if I don't have all 4 controls populated with a name, I get an
error message. Is there a way I can re-write this a bit in case someone only
wants to email to 2 people and need to leave 2 of the fields on the form
blank? Thank you.

(part of the code)
Dim recip(5) As Variant
recip(0) = (Me.EmailCC1)
recip(1) = (Me.[EmailCC2])
recip(2) = (Me.[EmailCC3])
recip(3) = (Me.[EmailCC4])

doc.COPYTo = recip
 
That shouldn't be! What about

ReDim Preserve Recip(3) As Variant

?

If you know how many recipients you're going to have in advance, you could
also try:

Dim recip() As Variant
Dim n As Long

n = 3
ReDim recip(n)
recip(0) = (Me.EmailCC1)
recip(1) = (Me.[EmailCC2])
recip(2) = (Me.[EmailCC3])
recip(3) = (Me.[EmailCC4])

BTW, are you sure they need to be declared as Variants? Would Text work as
well?

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)



Alex said:
Thanks Douglas. When I add ReDim Preserve Recip(3) I get a message:
"Array
Already Dimensioned". Do you know why? Thanks.

Douglas J Steele said:
Dim recip(5) As Variant
recip(0) = (Me.EmailCC1)
recip(1) = (Me.[EmailCC2])
recip(2) = (Me.[EmailCC3])
recip(3) = (Me.[EmailCC4])
ReDim Preserve recip(3)


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


Alex said:
I am using the following code snipit to send an email from Access to
recipients listed in the following form controls. Everything works
great
except that if I don't have all 4 controls populated with a name, I get
an
error message. Is there a way I can re-write this a bit in case
someone only
wants to email to 2 people and need to leave 2 of the fields on the
form
blank? Thank you.

(part of the code)
Dim recip(5) As Variant
recip(0) = (Me.EmailCC1)
recip(1) = (Me.[EmailCC2])
recip(2) = (Me.[EmailCC3])
recip(3) = (Me.[EmailCC4])

doc.COPYTo = recip
 
If you want to redim an array, I've found that it is best not to specify the
dimension size when you first declare it. If I do specify the size, I get
an error message when I attempt to Redim it.

Dim Recip() as Variant
Redim Recip(5)
....
Redim Preserve Recip(3)


Douglas J. Steele said:
That shouldn't be! What about

ReDim Preserve Recip(3) As Variant

?

If you know how many recipients you're going to have in advance, you could
also try:

Dim recip() As Variant
Dim n As Long

n = 3
ReDim recip(n)
recip(0) = (Me.EmailCC1)
recip(1) = (Me.[EmailCC2])
recip(2) = (Me.[EmailCC3])
recip(3) = (Me.[EmailCC4])

BTW, are you sure they need to be declared as Variants? Would Text work as
well?

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)



Alex said:
Thanks Douglas. When I add ReDim Preserve Recip(3) I get a message:
"Array
Already Dimensioned". Do you know why? Thanks.

Douglas J Steele said:
Dim recip(5) As Variant
recip(0) = (Me.EmailCC1)
recip(1) = (Me.[EmailCC2])
recip(2) = (Me.[EmailCC3])
recip(3) = (Me.[EmailCC4])
ReDim Preserve recip(3)


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


I am using the following code snipit to send an email from Access to
recipients listed in the following form controls. Everything works
great
except that if I don't have all 4 controls populated with a name, I
get an
error message. Is there a way I can re-write this a bit in case
someone
only
wants to email to 2 people and need to leave 2 of the fields on the
form
blank? Thank you.

(part of the code)
Dim recip(5) As Variant
recip(0) = (Me.EmailCC1)
recip(1) = (Me.[EmailCC2])
recip(2) = (Me.[EmailCC3])
recip(3) = (Me.[EmailCC4])

doc.COPYTo = recip
 
I'm sure this is developer error, I'm still having problems. I got rid of
the "Array
Already Dimensioned" error msg. by changing the code to:

Dim Recip() As Variant
ReDim Recip(5)
Recip(0) = (Me.[EmailCC1])
Recip(1) = (Me.[EmailCC2])
Recip(2) = (Me.[EmailCC3])
Recip(3) = (Me.[EmailCC4])
ReDim Preserve Recip(3)

'add'l code . . .

doc.COPYTo = Recip



But now I'm getting my original error message "Could not create field %1" in
the code: doc.COPYTo = Recip

I'm not familiar with using variant and I'm not sure what the 5 represents
in Recip (5). Here's what I'd like to happen: I have 4 fields on my form
which allows user to CC 0 - 4 people on the email. I'm getting the Could not
create field %1 if any of the 4 fields = null. Thanks for your suggestions.

John Spencer said:
If you want to redim an array, I've found that it is best not to specify the
dimension size when you first declare it. If I do specify the size, I get
an error message when I attempt to Redim it.

Dim Recip() as Variant
Redim Recip(5)
....
Redim Preserve Recip(3)


Douglas J. Steele said:
That shouldn't be! What about

ReDim Preserve Recip(3) As Variant

?

If you know how many recipients you're going to have in advance, you could
also try:

Dim recip() As Variant
Dim n As Long

n = 3
ReDim recip(n)
recip(0) = (Me.EmailCC1)
recip(1) = (Me.[EmailCC2])
recip(2) = (Me.[EmailCC3])
recip(3) = (Me.[EmailCC4])

BTW, are you sure they need to be declared as Variants? Would Text work as
well?

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)



Alex said:
Thanks Douglas. When I add ReDim Preserve Recip(3) I get a message:
"Array
Already Dimensioned". Do you know why? Thanks.

:

Dim recip(5) As Variant
recip(0) = (Me.EmailCC1)
recip(1) = (Me.[EmailCC2])
recip(2) = (Me.[EmailCC3])
recip(3) = (Me.[EmailCC4])
ReDim Preserve recip(3)


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


I am using the following code snipit to send an email from Access to
recipients listed in the following form controls. Everything works
great
except that if I don't have all 4 controls populated with a name, I
get an
error message. Is there a way I can re-write this a bit in case
someone
only
wants to email to 2 people and need to leave 2 of the fields on the
form
blank? Thank you.

(part of the code)
Dim recip(5) As Variant
recip(0) = (Me.EmailCC1)
recip(1) = (Me.[EmailCC2])
recip(2) = (Me.[EmailCC3])
recip(3) = (Me.[EmailCC4])

doc.COPYTo = recip
 
It would probably help to see all of the relevant code. If you got the code
from the web, knowing where it came from might help as well...

--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Alex said:
I'm sure this is developer error, I'm still having problems. I got rid of
the "Array
Already Dimensioned" error msg. by changing the code to:

Dim Recip() As Variant
ReDim Recip(5)
Recip(0) = (Me.[EmailCC1])
Recip(1) = (Me.[EmailCC2])
Recip(2) = (Me.[EmailCC3])
Recip(3) = (Me.[EmailCC4])
ReDim Preserve Recip(3)

'add'l code . . .

doc.COPYTo = Recip



But now I'm getting my original error message "Could not create field %1" in
the code: doc.COPYTo = Recip

I'm not familiar with using variant and I'm not sure what the 5 represents
in Recip (5). Here's what I'd like to happen: I have 4 fields on my form
which allows user to CC 0 - 4 people on the email. I'm getting the Could not
create field %1 if any of the 4 fields = null. Thanks for your suggestions.

John Spencer said:
If you want to redim an array, I've found that it is best not to specify the
dimension size when you first declare it. If I do specify the size, I get
an error message when I attempt to Redim it.

Dim Recip() as Variant
Redim Recip(5)
....
Redim Preserve Recip(3)


Douglas J. Steele said:
That shouldn't be! What about

ReDim Preserve Recip(3) As Variant

?

If you know how many recipients you're going to have in advance, you could
also try:

Dim recip() As Variant
Dim n As Long

n = 3
ReDim recip(n)
recip(0) = (Me.EmailCC1)
recip(1) = (Me.[EmailCC2])
recip(2) = (Me.[EmailCC3])
recip(3) = (Me.[EmailCC4])

BTW, are you sure they need to be declared as Variants? Would Text work as
well?

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)



Thanks Douglas. When I add ReDim Preserve Recip(3) I get a message:
"Array
Already Dimensioned". Do you know why? Thanks.

:

Dim recip(5) As Variant
recip(0) = (Me.EmailCC1)
recip(1) = (Me.[EmailCC2])
recip(2) = (Me.[EmailCC3])
recip(3) = (Me.[EmailCC4])
ReDim Preserve recip(3)


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


I am using the following code snipit to send an email from Access to
recipients listed in the following form controls. Everything works
great
except that if I don't have all 4 controls populated with a name, I
get an
error message. Is there a way I can re-write this a bit in case
someone
only
wants to email to 2 people and need to leave 2 of the fields on the
form
blank? Thank you.

(part of the code)
Dim recip(5) As Variant
recip(0) = (Me.EmailCC1)
recip(1) = (Me.[EmailCC2])
recip(2) = (Me.[EmailCC3])
recip(3) = (Me.[EmailCC4])

doc.COPYTo = recip
 
Doug,

Below is my code. I can't remember where I originally found some of the
code, but I've added things to make my button work the way I need it to.
Continued thanks for your help.

Public Sub SendNotesMail_Click()

Dim s As Object
Dim db As Object
Dim doc As Object
Dim rtItem As Object
Dim Server As String, Database As String
Dim strError As String
Dim Subject As String
Dim BodyText As String
Dim Attachment As String
Dim AttachME As Object
Dim EmbedObj As Object
Dim Recip() As Variant
ReDim Recip(5)
Recip(0) = (Me.[EmailCC1])
Recip(1) = (Me.[EmailCC2])
Recip(2) = (Me.[EmailCC3])
Recip(3) = (Me.[EmailCC4])
ReDim Preserve Recip(3)

'Dim Recip() As Variant
'ReDim Recip(5)
'....
'ReDim Preserve Recip(3)



'Refreshes form, sets query filter and creates .snp file
Me.Refresh
Application.CurrentDb.QueryDefs("EmailQuery").SQL = "Select * From
ProblemLogTable Where ProblemNumber = " & Me.[ProblemNumber]
DoCmd.OutputTo acOutputReport, "EmailQuery", acFormatSNP,
"M:\Operations\Weld Tech Database\WELD_Tech_Log.snp", False

'Check for email addressee
If Len(Me.VendorEmail.Value & "") = 0 Then
MsgBox "You must select at least one email address."
DoCmd.GoToControl "VendorEmail"
Exit Sub
End If


'startup Lotus notes and get object handle
Set s = CreateObject("Notes.notesSession")
Server = s.GETENVIRONMENTSTRING("MailServer", True)
Database = s.GETENVIRONMENTSTRING("MailFile", True)
Set db = s.getdatabase(Server, Database)

On Error GoTo ErrorLogon
'see if user is logged on
Set doc = db.createdocument
On Error GoTo 0

doc.Form = "Memo"
doc.importance = "3" '(Where 1=Urgent, 2= Normal, 3= FYI)


'Send an e-mail to
doc.SENDTO = (Me![Vendor1Email])
doc.COPYTo = Recip
doc.RETURNRECEIPT = "1"
doc.Subject = (Me![EmailSubject])

'If Attachment <> "" Then
Set rtItem = doc.CREATERICHTEXTITEM("M:\Operations\Weld Tech
Database\WELD_Tech_Log.snp")
Set EmbedObj = rtItem.EMBEDOBJECT(1454, "", "M:\Operations\Weld Tech
Database\WELD_Tech_Log.snp")
'doc.CREATERICHTEXTITEM ("M:\HR\Class Files\WELD_Log.snp")
'End If

Dim Msg, Style, Title, Help, Ctxt, Response, MyString
Msg = "Are you ready to send the email and close the Weld Tech Problem Log?"
' Define message.
Style = vbYesNo + vbCritical + vbDefaultButton2 ' Define buttons.
Title = "Continue?" ' Define title.
'Help = "DEMO.HLP" ' Define Help file.
Ctxt = 1000 ' Define topic
' context.
' Display message.
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbYes Then ' User chose Yes.
Refresh
Call doc.Send(False)
Call doc.Save(True, True)

Set doc = Nothing
Set db = Nothing
Set s = Nothing
Set rtItem = Nothing

DoCmd.Close acForm, "Weld Tech Problem Log", acSaveNo

ElseIf Response = vbNo Then ' User chose No.
Exit Sub
End If

ErrorLogon:
If Err.Number = 7063 Then
MsgBox " You must first logon to Lotus Notes"
Set doc = Nothing
Set db = Nothing
Set s = Nothing
Set rtItem = Nothing
End If


MsgBox "Your Weld Problem Log has been sent."

End Sub


Douglas J Steele said:
It would probably help to see all of the relevant code. If you got the code
from the web, knowing where it came from might help as well...

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


Alex said:
I'm sure this is developer error, I'm still having problems. I got rid of
the "Array
Already Dimensioned" error msg. by changing the code to:

Dim Recip() As Variant
ReDim Recip(5)
Recip(0) = (Me.[EmailCC1])
Recip(1) = (Me.[EmailCC2])
Recip(2) = (Me.[EmailCC3])
Recip(3) = (Me.[EmailCC4])
ReDim Preserve Recip(3)

'add'l code . . .

doc.COPYTo = Recip



But now I'm getting my original error message "Could not create field %1" in
the code: doc.COPYTo = Recip

I'm not familiar with using variant and I'm not sure what the 5 represents
in Recip (5). Here's what I'd like to happen: I have 4 fields on my form
which allows user to CC 0 - 4 people on the email. I'm getting the Could not
create field %1 if any of the 4 fields = null. Thanks for your suggestions.

John Spencer said:
If you want to redim an array, I've found that it is best not to specify the
dimension size when you first declare it. If I do specify the size, I get
an error message when I attempt to Redim it.

Dim Recip() as Variant
Redim Recip(5)
....
Redim Preserve Recip(3)


That shouldn't be! What about

ReDim Preserve Recip(3) As Variant

?

If you know how many recipients you're going to have in advance, you could
also try:

Dim recip() As Variant
Dim n As Long

n = 3
ReDim recip(n)
recip(0) = (Me.EmailCC1)
recip(1) = (Me.[EmailCC2])
recip(2) = (Me.[EmailCC3])
recip(3) = (Me.[EmailCC4])

BTW, are you sure they need to be declared as Variants? Would Text work as
well?

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)



Thanks Douglas. When I add ReDim Preserve Recip(3) I get a message:
"Array
Already Dimensioned". Do you know why? Thanks.

:

Dim recip(5) As Variant
recip(0) = (Me.EmailCC1)
recip(1) = (Me.[EmailCC2])
recip(2) = (Me.[EmailCC3])
recip(3) = (Me.[EmailCC4])
ReDim Preserve recip(3)


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


I am using the following code snipit to send an email from Access to
recipients listed in the following form controls. Everything works
great
except that if I don't have all 4 controls populated with a name, I
get an
error message. Is there a way I can re-write this a bit in case
someone
only
wants to email to 2 people and need to leave 2 of the fields on the
form
blank? Thank you.

(part of the code)
Dim recip(5) As Variant
recip(0) = (Me.EmailCC1)
recip(1) = (Me.[EmailCC2])
recip(2) = (Me.[EmailCC3])
recip(3) = (Me.[EmailCC4])

doc.COPYTo = recip
 
Nothing jumps out as incorrect in that code.

You sure that Me.[EmailCC1], Me.[EmailCC2] etc. all have values? (For that
matter, if you only have 4 text boxes to contain CC names, why are you
declaring the array as having 6 elements in the first place?)

Try:

Dim Recip() As Variant
Dim ctlCurr As Control
Dim intLoop As Integer

For intLoop = 0 To 3
Set ctlCurr = Me.Controls("EmailCC" & (intLoop + 1))
If Len(ctlCurr & "") > 0 Then
ReDim Preserve Recip(intLoop)
Recip(intLoop - 1) = ctlCurr
End If
Next intLoop

rather than

Dim Recip() As Variant

ReDim Recip(5)
Recip(0) = (Me.[EmailCC1])
Recip(1) = (Me.[EmailCC2])
Recip(2) = (Me.[EmailCC3])
Recip(3) = (Me.[EmailCC4])
ReDim Preserve Recip(3)

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)



Alex said:
Doug,

Below is my code. I can't remember where I originally found some of the
code, but I've added things to make my button work the way I need it to.
Continued thanks for your help.

Public Sub SendNotesMail_Click()

Dim s As Object
Dim db As Object
Dim doc As Object
Dim rtItem As Object
Dim Server As String, Database As String
Dim strError As String
Dim Subject As String
Dim BodyText As String
Dim Attachment As String
Dim AttachME As Object
Dim EmbedObj As Object
Dim Recip() As Variant
ReDim Recip(5)
Recip(0) = (Me.[EmailCC1])
Recip(1) = (Me.[EmailCC2])
Recip(2) = (Me.[EmailCC3])
Recip(3) = (Me.[EmailCC4])
ReDim Preserve Recip(3)

'Dim Recip() As Variant
'ReDim Recip(5)
'....
'ReDim Preserve Recip(3)



'Refreshes form, sets query filter and creates .snp file
Me.Refresh
Application.CurrentDb.QueryDefs("EmailQuery").SQL = "Select * From
ProblemLogTable Where ProblemNumber = " & Me.[ProblemNumber]
DoCmd.OutputTo acOutputReport, "EmailQuery", acFormatSNP,
"M:\Operations\Weld Tech Database\WELD_Tech_Log.snp", False

'Check for email addressee
If Len(Me.VendorEmail.Value & "") = 0 Then
MsgBox "You must select at least one email address."
DoCmd.GoToControl "VendorEmail"
Exit Sub
End If


'startup Lotus notes and get object handle
Set s = CreateObject("Notes.notesSession")
Server = s.GETENVIRONMENTSTRING("MailServer", True)
Database = s.GETENVIRONMENTSTRING("MailFile", True)
Set db = s.getdatabase(Server, Database)

On Error GoTo ErrorLogon
'see if user is logged on
Set doc = db.createdocument
On Error GoTo 0

doc.Form = "Memo"
doc.importance = "3" '(Where 1=Urgent, 2= Normal, 3= FYI)


'Send an e-mail to
doc.SENDTO = (Me![Vendor1Email])
doc.COPYTo = Recip
doc.RETURNRECEIPT = "1"
doc.Subject = (Me![EmailSubject])

'If Attachment <> "" Then
Set rtItem = doc.CREATERICHTEXTITEM("M:\Operations\Weld Tech
Database\WELD_Tech_Log.snp")
Set EmbedObj = rtItem.EMBEDOBJECT(1454, "", "M:\Operations\Weld Tech
Database\WELD_Tech_Log.snp")
'doc.CREATERICHTEXTITEM ("M:\HR\Class Files\WELD_Log.snp")
'End If

Dim Msg, Style, Title, Help, Ctxt, Response, MyString
Msg = "Are you ready to send the email and close the Weld Tech Problem
Log?"
' Define message.
Style = vbYesNo + vbCritical + vbDefaultButton2 ' Define buttons.
Title = "Continue?" ' Define title.
'Help = "DEMO.HLP" ' Define Help file.
Ctxt = 1000 ' Define topic
' context.
' Display message.
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbYes Then ' User chose Yes.
Refresh
Call doc.Send(False)
Call doc.Save(True, True)

Set doc = Nothing
Set db = Nothing
Set s = Nothing
Set rtItem = Nothing

DoCmd.Close acForm, "Weld Tech Problem Log", acSaveNo

ElseIf Response = vbNo Then ' User chose No.
Exit Sub
End If

ErrorLogon:
If Err.Number = 7063 Then
MsgBox " You must first logon to Lotus Notes"
Set doc = Nothing
Set db = Nothing
Set s = Nothing
Set rtItem = Nothing
End If


MsgBox "Your Weld Problem Log has been sent."

End Sub


Douglas J Steele said:
It would probably help to see all of the relevant code. If you got the
code
from the web, knowing where it came from might help as well...

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


Alex said:
I'm sure this is developer error, I'm still having problems. I got rid
of
the "Array
Already Dimensioned" error msg. by changing the code to:

Dim Recip() As Variant
ReDim Recip(5)
Recip(0) = (Me.[EmailCC1])
Recip(1) = (Me.[EmailCC2])
Recip(2) = (Me.[EmailCC3])
Recip(3) = (Me.[EmailCC4])
ReDim Preserve Recip(3)

'add'l code . . .

doc.COPYTo = Recip



But now I'm getting my original error message "Could not create field
%1" in
the code: doc.COPYTo = Recip

I'm not familiar with using variant and I'm not sure what the 5
represents
in Recip (5). Here's what I'd like to happen: I have 4 fields on my
form
which allows user to CC 0 - 4 people on the email. I'm getting the
Could not
create field %1 if any of the 4 fields = null. Thanks for your suggestions.

:

If you want to redim an array, I've found that it is best not to
specify the
dimension size when you first declare it. If I do specify the size,
I get
an error message when I attempt to Redim it.

Dim Recip() as Variant
Redim Recip(5)
....
Redim Preserve Recip(3)


message
That shouldn't be! What about

ReDim Preserve Recip(3) As Variant

?

If you know how many recipients you're going to have in advance,
you could
also try:

Dim recip() As Variant
Dim n As Long

n = 3
ReDim recip(n)
recip(0) = (Me.EmailCC1)
recip(1) = (Me.[EmailCC2])
recip(2) = (Me.[EmailCC3])
recip(3) = (Me.[EmailCC4])

BTW, are you sure they need to be declared as Variants? Would Text work as
well?

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)



Thanks Douglas. When I add ReDim Preserve Recip(3) I get a
message:
"Array
Already Dimensioned". Do you know why? Thanks.

:

Dim recip(5) As Variant
recip(0) = (Me.EmailCC1)
recip(1) = (Me.[EmailCC2])
recip(2) = (Me.[EmailCC3])
recip(3) = (Me.[EmailCC4])
ReDim Preserve recip(3)


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


I am using the following code snipit to send an email from
Access to
recipients listed in the following form controls. Everything works
great
except that if I don't have all 4 controls populated with a
name, I
get an
error message. Is there a way I can re-write this a bit in
case
someone
only
wants to email to 2 people and need to leave 2 of the fields on the
form
blank? Thank you.

(part of the code)
Dim recip(5) As Variant
recip(0) = (Me.EmailCC1)
recip(1) = (Me.[EmailCC2])
recip(2) = (Me.[EmailCC3])
recip(3) = (Me.[EmailCC4])

doc.COPYTo = recip
 
The code you suggested works much better. However, if I have an address in
the field EmailCC1, I get an error msg. "script is out of range" on
Recip(intLoop - 1) = ctlCurr. If there is no name is EmailCC1 and there are
names in any combination of EmailCC2, EmailCC3 or EmailCC4, the code works
great. Also, if I don't have name in any of the EmailCC fields, I get a msg
"Automation error. The server threw an exception". The code being debugged
during this message is doc.CopyTo = Recip.

Thanks for hanging in there with me. I really appreciate it.

Douglas J. Steele said:
Nothing jumps out as incorrect in that code.

You sure that Me.[EmailCC1], Me.[EmailCC2] etc. all have values? (For that
matter, if you only have 4 text boxes to contain CC names, why are you
declaring the array as having 6 elements in the first place?)

Try:

Dim Recip() As Variant
Dim ctlCurr As Control
Dim intLoop As Integer

For intLoop = 0 To 3
Set ctlCurr = Me.Controls("EmailCC" & (intLoop + 1))
If Len(ctlCurr & "") > 0 Then
ReDim Preserve Recip(intLoop)
Recip(intLoop - 1) = ctlCurr
End If
Next intLoop

rather than

Dim Recip() As Variant

ReDim Recip(5)
Recip(0) = (Me.[EmailCC1])
Recip(1) = (Me.[EmailCC2])
Recip(2) = (Me.[EmailCC3])
Recip(3) = (Me.[EmailCC4])
ReDim Preserve Recip(3)

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)



Alex said:
Doug,

Below is my code. I can't remember where I originally found some of the
code, but I've added things to make my button work the way I need it to.
Continued thanks for your help.

Public Sub SendNotesMail_Click()

Dim s As Object
Dim db As Object
Dim doc As Object
Dim rtItem As Object
Dim Server As String, Database As String
Dim strError As String
Dim Subject As String
Dim BodyText As String
Dim Attachment As String
Dim AttachME As Object
Dim EmbedObj As Object
Dim Recip() As Variant
ReDim Recip(5)
Recip(0) = (Me.[EmailCC1])
Recip(1) = (Me.[EmailCC2])
Recip(2) = (Me.[EmailCC3])
Recip(3) = (Me.[EmailCC4])
ReDim Preserve Recip(3)

'Dim Recip() As Variant
'ReDim Recip(5)
'....
'ReDim Preserve Recip(3)



'Refreshes form, sets query filter and creates .snp file
Me.Refresh
Application.CurrentDb.QueryDefs("EmailQuery").SQL = "Select * From
ProblemLogTable Where ProblemNumber = " & Me.[ProblemNumber]
DoCmd.OutputTo acOutputReport, "EmailQuery", acFormatSNP,
"M:\Operations\Weld Tech Database\WELD_Tech_Log.snp", False

'Check for email addressee
If Len(Me.VendorEmail.Value & "") = 0 Then
MsgBox "You must select at least one email address."
DoCmd.GoToControl "VendorEmail"
Exit Sub
End If


'startup Lotus notes and get object handle
Set s = CreateObject("Notes.notesSession")
Server = s.GETENVIRONMENTSTRING("MailServer", True)
Database = s.GETENVIRONMENTSTRING("MailFile", True)
Set db = s.getdatabase(Server, Database)

On Error GoTo ErrorLogon
'see if user is logged on
Set doc = db.createdocument
On Error GoTo 0

doc.Form = "Memo"
doc.importance = "3" '(Where 1=Urgent, 2= Normal, 3= FYI)


'Send an e-mail to
doc.SENDTO = (Me![Vendor1Email])
doc.COPYTo = Recip
doc.RETURNRECEIPT = "1"
doc.Subject = (Me![EmailSubject])

'If Attachment <> "" Then
Set rtItem = doc.CREATERICHTEXTITEM("M:\Operations\Weld Tech
Database\WELD_Tech_Log.snp")
Set EmbedObj = rtItem.EMBEDOBJECT(1454, "", "M:\Operations\Weld Tech
Database\WELD_Tech_Log.snp")
'doc.CREATERICHTEXTITEM ("M:\HR\Class Files\WELD_Log.snp")
'End If

Dim Msg, Style, Title, Help, Ctxt, Response, MyString
Msg = "Are you ready to send the email and close the Weld Tech Problem
Log?"
' Define message.
Style = vbYesNo + vbCritical + vbDefaultButton2 ' Define buttons.
Title = "Continue?" ' Define title.
'Help = "DEMO.HLP" ' Define Help file.
Ctxt = 1000 ' Define topic
' context.
' Display message.
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbYes Then ' User chose Yes.
Refresh
Call doc.Send(False)
Call doc.Save(True, True)

Set doc = Nothing
Set db = Nothing
Set s = Nothing
Set rtItem = Nothing

DoCmd.Close acForm, "Weld Tech Problem Log", acSaveNo

ElseIf Response = vbNo Then ' User chose No.
Exit Sub
End If

ErrorLogon:
If Err.Number = 7063 Then
MsgBox " You must first logon to Lotus Notes"
Set doc = Nothing
Set db = Nothing
Set s = Nothing
Set rtItem = Nothing
End If


MsgBox "Your Weld Problem Log has been sent."

End Sub


Douglas J Steele said:
It would probably help to see all of the relevant code. If you got the
code
from the web, knowing where it came from might help as well...

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


I'm sure this is developer error, I'm still having problems. I got rid
of
the "Array
Already Dimensioned" error msg. by changing the code to:

Dim Recip() As Variant
ReDim Recip(5)
Recip(0) = (Me.[EmailCC1])
Recip(1) = (Me.[EmailCC2])
Recip(2) = (Me.[EmailCC3])
Recip(3) = (Me.[EmailCC4])
ReDim Preserve Recip(3)

'add'l code . . .

doc.COPYTo = Recip



But now I'm getting my original error message "Could not create field
%1"
in
the code: doc.COPYTo = Recip

I'm not familiar with using variant and I'm not sure what the 5
represents
in Recip (5). Here's what I'd like to happen: I have 4 fields on my
form
which allows user to CC 0 - 4 people on the email. I'm getting the
Could
not
create field %1 if any of the 4 fields = null. Thanks for your
suggestions.

:

If you want to redim an array, I've found that it is best not to
specify
the
dimension size when you first declare it. If I do specify the size,
I
get
an error message when I attempt to Redim it.

Dim Recip() as Variant
Redim Recip(5)
....
Redim Preserve Recip(3)


message
That shouldn't be! What about

ReDim Preserve Recip(3) As Variant

?

If you know how many recipients you're going to have in advance,
you
could
also try:

Dim recip() As Variant
Dim n As Long

n = 3
ReDim recip(n)
recip(0) = (Me.EmailCC1)
recip(1) = (Me.[EmailCC2])
recip(2) = (Me.[EmailCC3])
recip(3) = (Me.[EmailCC4])

BTW, are you sure they need to be declared as Variants? Would Text
work as
well?

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)



Thanks Douglas. When I add ReDim Preserve Recip(3) I get a
message:
"Array
Already Dimensioned". Do you know why? Thanks.

:

Dim recip(5) As Variant
recip(0) = (Me.EmailCC1)
recip(1) = (Me.[EmailCC2])
recip(2) = (Me.[EmailCC3])
recip(3) = (Me.[EmailCC4])
ReDim Preserve recip(3)


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


I am using the following code snipit to send an email from
Access
to
recipients listed in the following form controls. Everything
works
great
except that if I don't have all 4 controls populated with a
name,
I
get an
error message. Is there a way I can re-write this a bit in
case
someone
only
wants to email to 2 people and need to leave 2 of the fields on
the
 
Sorry, that should have been

Recip(intLoop) = ctlCurr

(I went through a couple of iterations of the code as I was typing, and
forgot to correct the code in one place!)

As to the second problem, you could add a boolean variable that you set to
True whenever you add anyone to the Recip array:

Dim Recip() As Variant
Dim booPopulated As Boolean
Dim ctlCurr As Control
Dim intLoop As Integer

booPopulated = False
For intLoop = 0 To 3
Set ctlCurr = Me.Controls("EmailCC" & (intLoop + 1))
If Len(ctlCurr & "") > 0 Then
ReDim Preserve Recip(intLoop)
Recip(intLoop - 1) = ctlCurr
booPopulated = True
End If
Next intLoop

Then, rather than simply

doc.COPYTo = Recip

use

If booPopulated = True Then
doc.COPYTo = Recip
End If

Alternatively, you could create a little function that checks whether or not
your array has been initialized:

Function ArrayInitialized(ArrayName) As Boolean
On Error Resume Next

Dim lngUBound As Long

lngUbound = UBound(ArrayName)
ArrayInitialized = (Err.Number = 0)
Err.Clear

End Function

then use

If ArrayInitialized(Recip) Then
doc.COPYTo = Recip
End If



--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Alex said:
The code you suggested works much better. However, if I have an address in
the field EmailCC1, I get an error msg. "script is out of range" on
Recip(intLoop - 1) = ctlCurr. If there is no name is EmailCC1 and there are
names in any combination of EmailCC2, EmailCC3 or EmailCC4, the code works
great. Also, if I don't have name in any of the EmailCC fields, I get a msg
"Automation error. The server threw an exception". The code being debugged
during this message is doc.CopyTo = Recip.

Thanks for hanging in there with me. I really appreciate it.

Douglas J. Steele said:
Nothing jumps out as incorrect in that code.

You sure that Me.[EmailCC1], Me.[EmailCC2] etc. all have values? (For that
matter, if you only have 4 text boxes to contain CC names, why are you
declaring the array as having 6 elements in the first place?)

Try:

Dim Recip() As Variant
Dim ctlCurr As Control
Dim intLoop As Integer

For intLoop = 0 To 3
Set ctlCurr = Me.Controls("EmailCC" & (intLoop + 1))
If Len(ctlCurr & "") > 0 Then
ReDim Preserve Recip(intLoop)
Recip(intLoop - 1) = ctlCurr
End If
Next intLoop

rather than

Dim Recip() As Variant

ReDim Recip(5)
Recip(0) = (Me.[EmailCC1])
Recip(1) = (Me.[EmailCC2])
Recip(2) = (Me.[EmailCC3])
Recip(3) = (Me.[EmailCC4])
ReDim Preserve Recip(3)

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)



Alex said:
Doug,

Below is my code. I can't remember where I originally found some of the
code, but I've added things to make my button work the way I need it to.
Continued thanks for your help.

Public Sub SendNotesMail_Click()

Dim s As Object
Dim db As Object
Dim doc As Object
Dim rtItem As Object
Dim Server As String, Database As String
Dim strError As String
Dim Subject As String
Dim BodyText As String
Dim Attachment As String
Dim AttachME As Object
Dim EmbedObj As Object
Dim Recip() As Variant
ReDim Recip(5)
Recip(0) = (Me.[EmailCC1])
Recip(1) = (Me.[EmailCC2])
Recip(2) = (Me.[EmailCC3])
Recip(3) = (Me.[EmailCC4])
ReDim Preserve Recip(3)

'Dim Recip() As Variant
'ReDim Recip(5)
'....
'ReDim Preserve Recip(3)



'Refreshes form, sets query filter and creates .snp file
Me.Refresh
Application.CurrentDb.QueryDefs("EmailQuery").SQL = "Select * From
ProblemLogTable Where ProblemNumber = " & Me.[ProblemNumber]
DoCmd.OutputTo acOutputReport, "EmailQuery", acFormatSNP,
"M:\Operations\Weld Tech Database\WELD_Tech_Log.snp", False

'Check for email addressee
If Len(Me.VendorEmail.Value & "") = 0 Then
MsgBox "You must select at least one email address."
DoCmd.GoToControl "VendorEmail"
Exit Sub
End If


'startup Lotus notes and get object handle
Set s = CreateObject("Notes.notesSession")
Server = s.GETENVIRONMENTSTRING("MailServer", True)
Database = s.GETENVIRONMENTSTRING("MailFile", True)
Set db = s.getdatabase(Server, Database)

On Error GoTo ErrorLogon
'see if user is logged on
Set doc = db.createdocument
On Error GoTo 0

doc.Form = "Memo"
doc.importance = "3" '(Where 1=Urgent, 2= Normal, 3= FYI)


'Send an e-mail to
doc.SENDTO = (Me![Vendor1Email])
doc.COPYTo = Recip
doc.RETURNRECEIPT = "1"
doc.Subject = (Me![EmailSubject])

'If Attachment <> "" Then
Set rtItem = doc.CREATERICHTEXTITEM("M:\Operations\Weld Tech
Database\WELD_Tech_Log.snp")
Set EmbedObj = rtItem.EMBEDOBJECT(1454, "", "M:\Operations\Weld Tech
Database\WELD_Tech_Log.snp")
'doc.CREATERICHTEXTITEM ("M:\HR\Class Files\WELD_Log.snp")
'End If

Dim Msg, Style, Title, Help, Ctxt, Response, MyString
Msg = "Are you ready to send the email and close the Weld Tech Problem
Log?"
' Define message.
Style = vbYesNo + vbCritical + vbDefaultButton2 ' Define buttons.
Title = "Continue?" ' Define title.
'Help = "DEMO.HLP" ' Define Help file.
Ctxt = 1000 ' Define topic
' context.
' Display message.
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbYes Then ' User chose Yes.
Refresh
Call doc.Send(False)
Call doc.Save(True, True)

Set doc = Nothing
Set db = Nothing
Set s = Nothing
Set rtItem = Nothing

DoCmd.Close acForm, "Weld Tech Problem Log", acSaveNo

ElseIf Response = vbNo Then ' User chose No.
Exit Sub
End If

ErrorLogon:
If Err.Number = 7063 Then
MsgBox " You must first logon to Lotus Notes"
Set doc = Nothing
Set db = Nothing
Set s = Nothing
Set rtItem = Nothing
End If


MsgBox "Your Weld Problem Log has been sent."

End Sub


:

It would probably help to see all of the relevant code. If you got the
code
from the web, knowing where it came from might help as well...

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


I'm sure this is developer error, I'm still having problems. I got rid
of
the "Array
Already Dimensioned" error msg. by changing the code to:

Dim Recip() As Variant
ReDim Recip(5)
Recip(0) = (Me.[EmailCC1])
Recip(1) = (Me.[EmailCC2])
Recip(2) = (Me.[EmailCC3])
Recip(3) = (Me.[EmailCC4])
ReDim Preserve Recip(3)

'add'l code . . .

doc.COPYTo = Recip



But now I'm getting my original error message "Could not create field
%1"
in
the code: doc.COPYTo = Recip

I'm not familiar with using variant and I'm not sure what the 5
represents
in Recip (5). Here's what I'd like to happen: I have 4 fields on my
form
which allows user to CC 0 - 4 people on the email. I'm getting the
Could
not
create field %1 if any of the 4 fields = null. Thanks for your
suggestions.

:

If you want to redim an array, I've found that it is best not to
specify
the
dimension size when you first declare it. If I do specify the size,
I
get
an error message when I attempt to Redim it.

Dim Recip() as Variant
Redim Recip(5)
....
Redim Preserve Recip(3)


message
That shouldn't be! What about

ReDim Preserve Recip(3) As Variant

?

If you know how many recipients you're going to have in advance,
you
could
also try:

Dim recip() As Variant
Dim n As Long

n = 3
ReDim recip(n)
recip(0) = (Me.EmailCC1)
recip(1) = (Me.[EmailCC2])
recip(2) = (Me.[EmailCC3])
recip(3) = (Me.[EmailCC4])

BTW, are you sure they need to be declared as Variants? Would Text
work as
well?

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)



Thanks Douglas. When I add ReDim Preserve Recip(3) I get a
message:
"Array
Already Dimensioned". Do you know why? Thanks.

:

Dim recip(5) As Variant
recip(0) = (Me.EmailCC1)
recip(1) = (Me.[EmailCC2])
recip(2) = (Me.[EmailCC3])
recip(3) = (Me.[EmailCC4])
ReDim Preserve recip(3)


--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


I am using the following code snipit to send an email from
Access
to
recipients listed in the following form controls. Everything
works
great
except that if I don't have all 4 controls populated with a
name,
I
get an
error message. Is there a way I can re-write this a bit in
case
someone
only
wants to email to 2 people and need to leave 2 of the fields on
the
 
Excellent; on both accounts. I fixed the first bit of code and used your
booPopulated suggestion for the second. Thanks again for hanging in there
with me.

Douglas J Steele said:
Sorry, that should have been

Recip(intLoop) = ctlCurr

(I went through a couple of iterations of the code as I was typing, and
forgot to correct the code in one place!)

As to the second problem, you could add a boolean variable that you set to
True whenever you add anyone to the Recip array:

Dim Recip() As Variant
Dim booPopulated As Boolean
Dim ctlCurr As Control
Dim intLoop As Integer

booPopulated = False
For intLoop = 0 To 3
Set ctlCurr = Me.Controls("EmailCC" & (intLoop + 1))
If Len(ctlCurr & "") > 0 Then
ReDim Preserve Recip(intLoop)
Recip(intLoop - 1) = ctlCurr
booPopulated = True
End If
Next intLoop

Then, rather than simply

doc.COPYTo = Recip

use

If booPopulated = True Then
doc.COPYTo = Recip
End If

Alternatively, you could create a little function that checks whether or not
your array has been initialized:

Function ArrayInitialized(ArrayName) As Boolean
On Error Resume Next

Dim lngUBound As Long

lngUbound = UBound(ArrayName)
ArrayInitialized = (Err.Number = 0)
Err.Clear

End Function

then use

If ArrayInitialized(Recip) Then
doc.COPYTo = Recip
End If



--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)


Alex said:
The code you suggested works much better. However, if I have an address in
the field EmailCC1, I get an error msg. "script is out of range" on
Recip(intLoop - 1) = ctlCurr. If there is no name is EmailCC1 and there are
names in any combination of EmailCC2, EmailCC3 or EmailCC4, the code works
great. Also, if I don't have name in any of the EmailCC fields, I get a msg
"Automation error. The server threw an exception". The code being debugged
during this message is doc.CopyTo = Recip.

Thanks for hanging in there with me. I really appreciate it.

Douglas J. Steele said:
Nothing jumps out as incorrect in that code.

You sure that Me.[EmailCC1], Me.[EmailCC2] etc. all have values? (For that
matter, if you only have 4 text boxes to contain CC names, why are you
declaring the array as having 6 elements in the first place?)

Try:

Dim Recip() As Variant
Dim ctlCurr As Control
Dim intLoop As Integer

For intLoop = 0 To 3
Set ctlCurr = Me.Controls("EmailCC" & (intLoop + 1))
If Len(ctlCurr & "") > 0 Then
ReDim Preserve Recip(intLoop)
Recip(intLoop - 1) = ctlCurr
End If
Next intLoop

rather than

Dim Recip() As Variant

ReDim Recip(5)
Recip(0) = (Me.[EmailCC1])
Recip(1) = (Me.[EmailCC2])
Recip(2) = (Me.[EmailCC3])
Recip(3) = (Me.[EmailCC4])
ReDim Preserve Recip(3)

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)



Doug,

Below is my code. I can't remember where I originally found some of the
code, but I've added things to make my button work the way I need it to.
Continued thanks for your help.

Public Sub SendNotesMail_Click()

Dim s As Object
Dim db As Object
Dim doc As Object
Dim rtItem As Object
Dim Server As String, Database As String
Dim strError As String
Dim Subject As String
Dim BodyText As String
Dim Attachment As String
Dim AttachME As Object
Dim EmbedObj As Object
Dim Recip() As Variant
ReDim Recip(5)
Recip(0) = (Me.[EmailCC1])
Recip(1) = (Me.[EmailCC2])
Recip(2) = (Me.[EmailCC3])
Recip(3) = (Me.[EmailCC4])
ReDim Preserve Recip(3)

'Dim Recip() As Variant
'ReDim Recip(5)
'....
'ReDim Preserve Recip(3)



'Refreshes form, sets query filter and creates .snp file
Me.Refresh
Application.CurrentDb.QueryDefs("EmailQuery").SQL = "Select * From
ProblemLogTable Where ProblemNumber = " & Me.[ProblemNumber]
DoCmd.OutputTo acOutputReport, "EmailQuery", acFormatSNP,
"M:\Operations\Weld Tech Database\WELD_Tech_Log.snp", False

'Check for email addressee
If Len(Me.VendorEmail.Value & "") = 0 Then
MsgBox "You must select at least one email address."
DoCmd.GoToControl "VendorEmail"
Exit Sub
End If


'startup Lotus notes and get object handle
Set s = CreateObject("Notes.notesSession")
Server = s.GETENVIRONMENTSTRING("MailServer", True)
Database = s.GETENVIRONMENTSTRING("MailFile", True)
Set db = s.getdatabase(Server, Database)

On Error GoTo ErrorLogon
'see if user is logged on
Set doc = db.createdocument
On Error GoTo 0

doc.Form = "Memo"
doc.importance = "3" '(Where 1=Urgent, 2= Normal, 3= FYI)


'Send an e-mail to
doc.SENDTO = (Me![Vendor1Email])
doc.COPYTo = Recip
doc.RETURNRECEIPT = "1"
doc.Subject = (Me![EmailSubject])

'If Attachment <> "" Then
Set rtItem = doc.CREATERICHTEXTITEM("M:\Operations\Weld Tech
Database\WELD_Tech_Log.snp")
Set EmbedObj = rtItem.EMBEDOBJECT(1454, "", "M:\Operations\Weld Tech
Database\WELD_Tech_Log.snp")
'doc.CREATERICHTEXTITEM ("M:\HR\Class Files\WELD_Log.snp")
'End If

Dim Msg, Style, Title, Help, Ctxt, Response, MyString
Msg = "Are you ready to send the email and close the Weld Tech Problem
Log?"
' Define message.
Style = vbYesNo + vbCritical + vbDefaultButton2 ' Define buttons.
Title = "Continue?" ' Define title.
'Help = "DEMO.HLP" ' Define Help file.
Ctxt = 1000 ' Define topic
' context.
' Display message.
Response = MsgBox(Msg, Style, Title, Help, Ctxt)
If Response = vbYes Then ' User chose Yes.
Refresh
Call doc.Send(False)
Call doc.Save(True, True)

Set doc = Nothing
Set db = Nothing
Set s = Nothing
Set rtItem = Nothing

DoCmd.Close acForm, "Weld Tech Problem Log", acSaveNo

ElseIf Response = vbNo Then ' User chose No.
Exit Sub
End If

ErrorLogon:
If Err.Number = 7063 Then
MsgBox " You must first logon to Lotus Notes"
Set doc = Nothing
Set db = Nothing
Set s = Nothing
Set rtItem = Nothing
End If


MsgBox "Your Weld Problem Log has been sent."

End Sub


:

It would probably help to see all of the relevant code. If you got the
code
from the web, knowing where it came from might help as well...

--
Doug Steele, Microsoft Access MVP
http://I.Am/DougSteele
(no e-mails, please!)


I'm sure this is developer error, I'm still having problems. I got rid
of
the "Array
Already Dimensioned" error msg. by changing the code to:

Dim Recip() As Variant
ReDim Recip(5)
Recip(0) = (Me.[EmailCC1])
Recip(1) = (Me.[EmailCC2])
Recip(2) = (Me.[EmailCC3])
Recip(3) = (Me.[EmailCC4])
ReDim Preserve Recip(3)

'add'l code . . .

doc.COPYTo = Recip



But now I'm getting my original error message "Could not create field
%1"
in
the code: doc.COPYTo = Recip

I'm not familiar with using variant and I'm not sure what the 5
represents
in Recip (5). Here's what I'd like to happen: I have 4 fields on my
form
which allows user to CC 0 - 4 people on the email. I'm getting the
Could
not
create field %1 if any of the 4 fields = null. Thanks for your
suggestions.

:

If you want to redim an array, I've found that it is best not to
specify
 
Back
Top