Body empty

D

David

I'm new to Outlook VBA, but was able to cobble this together.

After entering data in a reoccuring Appointment, I want to email the
results to the boss.

Sub EmailInspResult()
Dim NewMail As Outlook.MailItem
Dim Appt As Outlook.AppointmentItem

Set Sel = Application.ActiveExplorer.Selection

For I = 1 To Sel.Count
If Sel.Item(I).Class = olAppointment Then
Set Appt = Sel.Item(I)
Set NewMail = ThisOutlookSession.CreateItem(olMailItem)
NewMail.To = "(e-mail address removed)"
NewMail.Subject = Appt.Subject
NewMail.Body = Appt.Body
NewMail.Display
End If
Next

End Sub

Problem is, the Appt.Body field is always blank even though I know
there's information is the Appointment body area.

I've made sure to save the appt after making any changes, but it's
always empty.

Any help would be appreciated.
David
 
M

Michael Bauer

Hi David,

why do you know the Body property isn´t blank? Maybe Sel.Item(i) isn´t
the item you think of?
NewMail.Body = Appt.Body

Did you set a breakpoint into this line and check the properties?
 
D

David Sisson

You're right. I don't know what Sel(i) is actually.

What I'm after is the Subject and the Body of the appointment I am
currently viewing, stuffed into a email.

I have these reoccuring inspections that I have setup in Outlook
calendar. When I get the reminder, I perform the inspection, Open the
item (from the reminder dialog) and enter the results of the inspection
in the body (notes) area. Then I need to email those two items out as a
email.

I program alot in Word and use the range object more than Selection.
Does Outlook have a Range for the current viewed appointment? Like
ActiveAppointment? I've looked throught the object browser but can't
seem to find what I'm looking for.

When I step through the macro and hover over Appt.Body, it shows "".
However if I hover over Appt.Subject, it correctly returns the text I
have in the current Appt subject line.

Thanks for your response.
 
M

Michael Bauer

Hi David,

I´m missing something - I don´t really understand the relation between
the description below and your first post/code snippet. Anyway, hope, I
can help nevertheless.

1) There is no Range object in OL.

2) The current viewed object is calling ActiveInspector.CurrentItem. You
then have to check the object type of CurrentItem, because it´s not only
for Appointments.

Maybe this is the fault: Selection(i) can be the current viewed item by
chance but it doesn´t has to be.
 
D

David Sisson

In retrospect, I am confident that I am reading the correct Appointment
with

If Sel.Item(I).Class = olAppointment Then ...

because when I hover over Appt.Subject, (after stepping over Set Appt =
Sel.Item(I) ) , it correctly returns the text from the Subject line.

However, when I hover over Appt.Body, the variable is empty. This
should contain the text in the large notes area of the Appointment,
correct?
 
M

Michael Bauer

Hi David,
However, when I hover over Appt.Body, the variable is empty. This
should contain the text in the large notes area of the Appointment,
correct?

correct.

Do you have more than one item with the same subject? What happens if
you call Appt.Display, do you see the expected item (with a text in the
body)?

I can´t reproduce this behaviour. But there is an error because there is
no variable named ThisOutlookSession. Do you have this one declared?
 
D

David Sisson

Do you have more than one item with the same subject? What happens if
you call Appt.Display, do you see the expected item (with a text in the
body)?

OK That seems to be the problem Appt.Display brings up the first in
the series (dated 03/02), not the occurance (03/16).

So how do I pick the current occurance appointment? By date?

But while stepping though the code, I notice that Sel.count is always
one. (The series I assume.)

Should I be looking for the Appointment in a different manner than
Application.ActiveExplorer.Sel­ection ?
 
M

Michael Bauer

Hi David,

the Selection collection gives you access to the *selected* items. If
there is only one item selected then Selection.Count is 1.

For the recurrences please see the GetRecurrencePattern function and the
RecurrencePattern´s GetOccurence function.

And again: For handling the currently viewed item please use
ActiveInspector.CurrentItem instead of AcitveExplorer.Selection.

--
Viele Grüße
Michael Bauer


David Sisson said:
Do you have more than one item with the same subject? What happens if
you call Appt.Display, do you see the expected item (with a text in the
body)?

OK That seems to be the problem Appt.Display brings up the first in
the series (dated 03/02), not the occurance (03/16).

So how do I pick the current occurance appointment? By date?

But while stepping though the code, I notice that Sel.count is always
one. (The series I assume.)

Should I be looking for the Appointment in a different manner than
Application.ActiveExplorer.Sel­ection ?
 
D

David Sisson

Ahah!
2) The current viewed object is calling ActiveInspector.CurrentItem. You
then have to check the object type of CurrentItem, because it´s not only
for Appointments.

I read right over this in your last post.

Changed code to ActiveInspector.CurrentItem amd it worked as requested.

Thanks a lot.

(I have a Outlook programming book on the way :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top