Log in

View Full Version : Code works without recipient, but doesn't work with a recipient



nijohnson
06-07-2012, 07:55 AM
Hi all,

So I'm working away on a bit of code that takes an appointment and creates a few tasks from the appointment and checks to see if theirs an attachement on the appojntment before its sent off.

The code works fine when I have no other attendees. But as soon as the attendees are added, the code gets stcuk on opening the file attachment dialogue box. Bleh!!

I've attached the code below:


Public WithEvents myItem As Outlook.appointmentitem
Private Sub myItem_Write(Cancel As Boolean)
Dim myResult As Integer
Dim olApp As Outlook.Application
Dim olTsk As TaskItem
Dim olAppt As appointmentitem
Dim TskSubj As String
Dim ApptSubj As String
Dim olNS As Outlook.NameSpace
Dim myolApp As Outlook.Application

Set olApp = New Outlook.Application
Set olTsk = olApp.CreateItem(olTaskItem)

With olTsk
olTsk.DueDate = myItem.Start - 1
olTsk.Subject = myItem.Subject
olTsk.Subject = replace(olTsk.Subject, "BC Test/Review", "Send BCP Docs")
olTsk.Body = "Attending: " & myItem.RequiredAttendees
olTsk.ReminderSet = True
olTsk.ReminderTime = olTsk.DueDate & " " & Format("10:00 AM")
End With
olTsk.Save

Set olTsk = Nothing
Set olApp = Nothing

Set olApp = New Outlook.Application
Set olTsk = olApp.CreateItem(olTaskItem)

With olTsk
olTsk.DueDate = myItem.Start + 30
olTsk.Subject = myItem.Subject
olTsk.Body = "Attending: " & myItem.RequiredAttendees
olTsk.ReminderSet = True
olTsk.ReminderTime = olTsk.DueDate & " " & Format("10:00 AM")

olTsk.Subject = replace(olTsk.Subject, "BC Test/Review", "BCP Updates due")

End With

olTsk.Save

Set olTsk = Nothing
Set olApp = Nothing
Set olApp = New Outlook.Application
Set olTsk = olApp.CreateItem(olTaskItem)

With olTsk
olTsk.DueDate = myItem.Start + 20
olTsk.Subject = myItem.Subject
olTsk.Body = "Attending: " & myItem.RequiredAttendees
olTsk.ReminderSet = True
olTsk.ReminderTime = olTsk.DueDate & " " & Format("10:00 AM")

olTsk.Subject = replace(olTsk.Subject, "BC Test/Review", "BIA Team Leader Signature")

End With
olTsk.Save
Set olTsk = Nothing
Set olApp = Nothing
Set olApp = New Outlook.Application
Set olTsk = olApp.CreateItem(olTaskItem)

With olTsk
olTsk.DueDate = myItem.Start + 30
olTsk.Subject = myItem.Subject
olTsk.Body = "Attending: " & myItem.RequiredAttendees
olTsk.ReminderSet = True
olTsk.ReminderTime = olTsk.DueDate & " " & Format("10:00 AM")

olTsk.Subject = replace(olTsk.Subject, "BC Test/Review", "BIA Executive Approver Signature")
End With
olTsk.Save
Set olTsk = Nothing
Set olApp = Nothing

Set olApp = New Outlook.Application
Set olTsk = olApp.CreateItem(olTaskItem)

With olTsk
olTsk.DueDate = myItem.Start + 1
olTsk.Subject = myItem.Subject
olTsk.Body = "Attending: " & myItem.RequiredAttendees
olTsk.ReminderSet = True
olTsk.ReminderTime = olTsk.DueDate & " " & Format("10:00 AM")

olTsk.Subject = replace(olTsk.Subject, "BC Test/Review", "Send BIA Link")
End With
olTsk.Save
Set olTsk = Nothing
Set olApp = Nothing

Set olApp = New Outlook.Application
Set olTsk = olApp.CreateItem(olTaskItem)

With olTsk
olTsk.DueDate = myItem.Start + 30
olTsk.Subject = myItem.Subject
olTsk.Body = "Attending: " & myItem.RequiredAttendees
olTsk.ReminderSet = True
olTsk.ReminderTime = olTsk.DueDate & " " & Format("10:00 AM")

olTsk.Subject = replace(olTsk.Subject, "BC Test/Review", "LDRPS")
End With
olTsk.Save
Set olTsk = Nothing
Set olApp = Nothing

MSG1 = MsgBox("Are BCP and BIA attached?", vbYesNo, "Yadda?")
If MSG1 = vbYes Then
myItem.Send
Else
MsgBox "Dude! What are you thinking??"
Dim myInspector As Outlook.Inspector
Set myolApp = CreateObject("Outlook.Application")
Set myInspector = myItem.GetInspector
Application.ActiveInspector.CommandBars.findcontrol(ID:=1079).Execute
Exit Sub
End If
End Sub

The line that it gets stcu on is this:

Application.ActiveInspector.CommandBars.findcontrol(ID:=1079).Execute

Like I said, it works when run without an attendee to the appointment, but crashes when I add some one.

Any help would be much appriciated.

nijohnson
06-07-2012, 11:36 AM
AH HAH!!!! So, it seems that the code works with a recipient IF I am on the original appointment page. But If i click my little button on the add recipient page, it won't work. I suspect that it is because the UI changes, and the add recipient page is actually a new UI and thereby not selected by the inspector! YAY ME!

JP2112
06-07-2012, 12:10 PM
Looks like you got your solution.

http://stackoverflow.com/questions/10934534/how-to-add-attachments-to-appointmentitem-after-attendees-are-added