PDA

View Full Version : Solved: Using Categories



chrismc
01-29-2006, 04:28 AM
Hi,

I've got some code which allows me to search through my appointments at work and forward the details of certain ones to my home email address. I want to mark the appointments that have already been sent in such a way that they don't get sent next time I run the code. What I thought was that if I use the category field I could achieve this. The following code works fine for checking the category of the appointment (if I've set it manually for testing) and for giving the outgoing message a category. However, it doesn't seem to set the category for the appointment. Can you spot where I'm going wrong please?

Chris





If Appt.Categories <> "Sent" Then
Set myMail = CreateItem(olMailItem)

Set myMail = Appt.ForwardAsVcal
myMail.Recipients.Add AnEmailAddress
myMail.Subject = Appt.Subject & ": " & Appt.Location
myMail.Body = Appt.Location & vbCr & Appt.End
myMail.Categories = "SendNow"
myMail.DeferredDeliveryTime = sendtime
myMail.Send
Appt.Categories = "Sent"

End if

XLGibbs
01-29-2006, 06:56 AM
You may need to tie it into a loop....I am not that proficient at Outlook though, and I am just assuming that absent a loop of some sort, your if statement applies to the entire folder.... A loop would address each item on it's own merit....just a guess though as I am not sure when the Oultook experts will be around!

Dim AP as Appointment '? syntax?
For each AP in Appt.Categories
''your code in here as written"
Next AP

chrismc
01-29-2006, 12:24 PM
Thanks for your input Gibbs. You are right about needing a loop. I actually use




For Each Appt In myAppointments




If Appt.Categories <> "Sent" Then
Set myMail = CreateItem(olMailItem)


Set myMail = Appt.ForwardAsVcal
myMail.Recipients.Add AnEmailAddress
myMail.Subject = Appt.Subject & ": " & Appt.Location
myMail.Body = Appt.Location & vbCr & Appt.End
myMail.Categories = "SendNow"
myMail.DeferredDeliveryTime = sendtime
myMail.Send
Appt.Categories = "Sent"



End if


Next Appt


So what is happening is that each appointment is checked to make sure that it does not have the category "Sent". If it hasn't then it performs a number of actions. The test does work because any appointments that have been marked with category "Sent" are ignored.

The actions are to forward the appointment as a VCal by email and this works. The final action is to mark the appointment with the "Sent" category so that next time the code is run the appointments is ignored. This is the bit that is not happening and I can't see why.

Cheers


Chris

XLGibbs
01-29-2006, 12:57 PM
Hmmm, I have outlook but don't have any appointments or categories to test with.. but I think this may be it. You are probably writing to the category property but not saving the appointment as such...



For Each Appt In myAppointments

With Appt
If .Categories <> "Sent" Then

Set myMail = CreateItem(olMailItem)
Set myMail = .ForwardAsVcal
With myMail
.Recipients.Add AnEmailAddress
.Subject = Appt.Subject & ": " & Appt.Location
.Body = Appt.Location & vbCr & Appt.End
.Categories = "SendNow"
.DeferredDeliveryTime = sendtime
.Send
End With

.Categories = "Sent"
.Save
End If
End With

Next

chrismc
01-29-2006, 01:35 PM
Spot on.

Many thanks.

Chris