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