Alright so I've got this Outlook code written in VBA in Access. The first part, which works, records information about appointment times based on the required days before notification of certain contracts and then it adds them to the outlook calendar of the current user. This code works and is nested within a bunch of if statements because it only needs to trap certain appointments. The table I create with this code is later used to attempt to create an email that sends out multiple appointments by means of adding an attachment, this is where I am having trouble. First I will post the code that works and then the code that does not work.
This is the code that works:
[PHP] stSQL = "SELECT * FROM AddedToOutlook WHERE DatabaseReferen ceNumber = " _
& recSet1("Databa seReferenceNumb er2")
' (This beginning part is just checking another table to see if these appointments have already been added to Outlook.)
recSet6.Open stSQL, con6, adOpenKeyset, adLockOptimisti c
If recSet6.EOF Then
recSet6.AddNew
Dim objOutlookRecip As Outlook.Recipie nt
Dim outObj As Outlook.Applica tion
'Dim outItem As Outlook.Contact Item
Dim outAppt As Outlook.Appoint mentItem
Dim myattachments As Outlook.Attachm ent
'Set outItem = outObj.CreateIt em(olContactIte m)
Set outObj = CreateObject("o utlook.applicat ion")
Set outAppt = outObj.CreateIt em(olAppointmen tItem)
With recSet8
.AddNew
.Fields("Start" ) = recSet1.Fields( "NotificationDa te2") _
& " " & recSet1.Fields( "ApptTime2" )
.Fields("Subjec t") = "Contract Notification/End" & " " _
& recSet1.Fields( "DatabaseRefere nceNumber2") _
& " " & recSet1.Fields( "Vendor2")
.Fields("Body") = "Contract Notification/End" & " " _
& recSet1.Fields( "DatabaseRefere nceNumber2") _
& " " & recSet1.Fields( "Vendor2")
.Fields("Remind erMinutesBefore Start") = recSet1.Fields( "ReminderMinute s2")
.Update
End With
With outAppt
.Start = recSet1.Fields( "NotificationDa te2") _
& " " & recSet1.Fields( "ApptTime2" )
.Duration = .AllDayEvent
.Subject = "Contract Notification/End" & " " _
& recSet1.Fields( "DatabaseRefere nceNumber2") _
& " " & recSet1.Fields( "Vendor2")
.Body = "Contract Notification/End" & " " _
& recSet1.Fields( "DatabaseRefere nceNumber2") _
& " " & recSet1.Fields( "Vendor2")
.ReminderMinute sBeforeStart = recSet1.Fields( "ReminderMinute s2")
.ReminderSet = True
.RequiredAttend ees = "JPollard@phcs. com"
.Save
End With
'DoCmd.RunComma nd acCmdSaveRecord
recSet6.Fields( "AddedToOutlook ") = True
recSet6.Fields( "DatabaseRefere nceNumber") = recSet1.Fields( "DatabaseRefere nceNumber2")
recSet6.Update
End If[/PHP]
Which is later followed by this code which does not seem to work:
[PHP]Dim outMail As Outlook.MailIte m
Set outMail = outObj.CreateIt em(olMailItem)
Dim outAppt2 As Outlook.Appoint mentItem
Set myattachments = outMail.Attachm ent
' Fill out & send message...
outMail.To = recSet8.Fields( "RequiredAttend ees")
outMail.Subject = "Contract Notification/End..."
recSet8.MoveFir st
Do Until recSet8.EOF
outAppt.Start = recSet8.Fields( "Start")
outAppt.Duratio n = 15
outAppt.Subject = recSet8.Fields( "Subject")
outAppt.Body = recSet8.Fields( "Body")
outAppt.Reminde rMinutesBeforeS tart = recSet8.Fields( "ReminderMinute sBeforeStart")
outAppt.Reminde rSet = True
outAppt.Require dAttendees = recSet8.Fields( "RequiredAttend ees")
Set outAppt2 = outAppt
' (tried putting separate code in a module but didn't work either) DoCmd.OpenModul e "modAppointment "
Set myattachments = myattachments.A dd(outAppt)
recSet8.MoveNex t
Loop
outMail.Body = _
"HI"
outMail.Send
'For Each objOutlookRecip In .Recipients
'objOutlookReci p.Resolve
'Next
' Clean up...
Set outMail = Nothing
'Set outItem = Nothing
Set outObj = Nothing
Set outAppt = Nothing[/PHP]
It seems that it is possible because an earlier version of this code was able to add five appointments but only added the last appointment in the recordset which I checked and surely it had 5 records in the table (but this number will vary based on the number of contracts that require notification within a certain number of days) but if I have 5 records...and I say move first, it seems like the only thing I'm acheiving by running this .EOF loop is counting from 1 to 5 and then multiplying the last entry by it. So that didn't make much sense.
The older version of the code can be found here:
http://www.thescripts.com/forum/thread583157.html
The code for the larger part of this program which would help you understand the context of this function can be found here:
http://www.thescripts.com/forum/thread581521.html
although I don't think this is necessary to figure out the problem...but people always like to have more code :)
Any help with this would be greatly appreciated as I have been struggling with this for a while and Microsoft does not seem to offer any help with this...nor does anyone else for that matter.
Cheers,
Kosmös