Discussion:
PropertyChange event not working
(too old to reply)
Matt
2009-07-08 23:00:38 UTC
Permalink
I am trying to get the PropertyChange event to fire using MS Outlook
2003...
but for some reason it doesn't. Thought I could just set the variable
to the
AppointmentItem and use the WithEvents.
Any help is appreciated. Thanks, Matt (code below)


Option Explicit
Private WithEvents olDeletedItems As Items
Private WithEvents myOlItems As Items
Public WithEvents myAppItem As Outlook.AppointmentItem


Private Sub Application_Startup()


Dim objNS As NameSpace
Set objNS = Application.GetNamespace("MAPI")
Set olDeletedItems = objNS.GetDefaultFolder
(olFolderDeletedItems).Items
Set myOlItems = objNS.GetDefaultFolder(olFolderCalendar).Items
Set objNS = Nothing
End Sub


Private Sub Application_Quit()
Set olDeletedItems = Nothing
End Sub


Private Sub olDeletedItems_ItemAdd(ByVal Item As Object)
If InStr(1, Item.Subject, "Vacation") Then
MsgBox Item.Subject
End If

Set Item = Nothing
End Sub

Private Sub myOlItems_ItemChange(ByVal Item As Object)

Set myAppItem = Item
End Sub

Private Sub myAppItem_PropertyChange(ByVal Name As String)


If Name = "Subject" Then
MsgBox "yes"
End If


End Sub
Sue Mosher [MVP]
2009-07-09 03:58:30 UTC
Permalink
The item has already changed before your code instantiates the myAppItem
object. Only if you change it a second time will you get that event.

Maybe you should start at the beginning and explain what you're trying to
do, in what version of Outlook.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54
Post by Matt
I am trying to get the PropertyChange event to fire using MS Outlook
2003...
but for some reason it doesn't. Thought I could just set the variable
to the
AppointmentItem and use the WithEvents.
Any help is appreciated. Thanks, Matt (code below)
Option Explicit
Private WithEvents olDeletedItems As Items
Private WithEvents myOlItems As Items
Public WithEvents myAppItem As Outlook.AppointmentItem
Private Sub Application_Startup()
Dim objNS As NameSpace
Set objNS = Application.GetNamespace("MAPI")
Set olDeletedItems = objNS.GetDefaultFolder
(olFolderDeletedItems).Items
Set myOlItems = objNS.GetDefaultFolder(olFolderCalendar).Items
Set objNS = Nothing
End Sub
Private Sub Application_Quit()
Set olDeletedItems = Nothing
End Sub
Private Sub olDeletedItems_ItemAdd(ByVal Item As Object)
If InStr(1, Item.Subject, "Vacation") Then
MsgBox Item.Subject
End If
Set Item = Nothing
End Sub
Private Sub myOlItems_ItemChange(ByVal Item As Object)
Set myAppItem = Item
End Sub
Private Sub myAppItem_PropertyChange(ByVal Name As String)
If Name = "Subject" Then
MsgBox "yes"
End If
End Sub
Matt
2009-07-09 13:53:38 UTC
Permalink
I am just learning Outlook VBA and am trying to get the
hang of different objects and methods. I am running Outlook 2003
w/ Exchange

What I'm trying to do is flag an appointment when
the subject changes. (As you said, i had to change the subject
twice to fire the propertychange event, thanks).

Thanks,
Matt
Post by Sue Mosher [MVP]
The item has already changed before your code instantiates the myAppItem
object. Only if you change it a second time will you get that event.
Maybe you should start at the beginning and explain what you're trying to
do, in what version of Outlook.
--
Sue Mosher, Outlook MVP
     Jumpstart for Power Users and Administrators
   http://www.outlookcode.com/article.aspx?id=54
Post by Matt
I am trying to get the PropertyChange event to fire using MS Outlook
2003...
but for some reason it doesn't. Thought I could just set the variable
to the
AppointmentItem and use the WithEvents.
Any help is appreciated. Thanks, Matt (code below)
Option Explicit
Private WithEvents olDeletedItems As Items
Private WithEvents myOlItems As Items
Public WithEvents myAppItem As Outlook.AppointmentItem
Private Sub Application_Startup()
  Dim objNS As NameSpace
   Set objNS = Application.GetNamespace("MAPI")
   Set olDeletedItems = objNS.GetDefaultFolder
(olFolderDeletedItems).Items
 Set myOlItems = objNS.GetDefaultFolder(olFolderCalendar).Items
   Set objNS = Nothing
    End Sub
Private Sub Application_Quit()
 Set olDeletedItems = Nothing
 End Sub
Private Sub olDeletedItems_ItemAdd(ByVal Item As Object)
 If InStr(1, Item.Subject, "Vacation") Then
 MsgBox Item.Subject
 End If
   Set Item = Nothing
End Sub
Private Sub myOlItems_ItemChange(ByVal Item As Object)
Set myAppItem = Item
End Sub
Private Sub myAppItem_PropertyChange(ByVal Name As String)
If Name = "Subject" Then
MsgBox "yes"
End If
End Sub- Hide quoted text -
- Show quoted text -
Sue Mosher [MVP]
2009-07-09 14:48:21 UTC
Permalink
I'm afraid that's a task that is well beyond "just learning Outlook VBA." To
handle that scenario in VBA code would require either maintaining a record
of all the subjects of all the appointments or writing a wrapper class
module to handle events for any item that the user might change. Both are
relatively advanced techniques.

Your scenario is much more suited to an Outlook custom form, which can have
VBScript code behind it to work with item-level events such as
PropertyChange. If you want to explore that approach, see
http://www.outlookcode.com/article.aspx?ID=35 for custom form basics and
http://www.outlookcode.com/article.aspx?ID=38 for particulars on
PropertyChange.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Matt" <***@yahoo.com> wrote in message news:2b83303d-e452-47c5-b218-***@d32g2000yqh.googlegroups.com...
I am just learning Outlook VBA and am trying to get the
hang of different objects and methods. I am running Outlook 2003
w/ Exchange

What I'm trying to do is flag an appointment when
the subject changes. (As you said, i had to change the subject
twice to fire the propertychange event, thanks).

Thanks,
Matt
Post by Sue Mosher [MVP]
The item has already changed before your code instantiates the myAppItem
object. Only if you change it a second time will you get that event.
Maybe you should start at the beginning and explain what you're trying to
do, in what version of Outlook.
Post by Matt
I am trying to get the PropertyChange event to fire using MS Outlook
2003...
but for some reason it doesn't. Thought I could just set the variable
to the
AppointmentItem and use the WithEvents.
Any help is appreciated. Thanks, Matt (code below)
Option Explicit
Private WithEvents olDeletedItems As Items
Private WithEvents myOlItems As Items
Public WithEvents myAppItem As Outlook.AppointmentItem
Private Sub Application_Startup()
Dim objNS As NameSpace
Set objNS = Application.GetNamespace("MAPI")
Set olDeletedItems = objNS.GetDefaultFolder
(olFolderDeletedItems).Items
Set myOlItems = objNS.GetDefaultFolder(olFolderCalendar).Items
Set objNS = Nothing
End Sub
Private Sub Application_Quit()
Set olDeletedItems = Nothing
End Sub
Private Sub olDeletedItems_ItemAdd(ByVal Item As Object)
If InStr(1, Item.Subject, "Vacation") Then
MsgBox Item.Subject
End If
Set Item = Nothing
End Sub
Private Sub myOlItems_ItemChange(ByVal Item As Object)
Set myAppItem = Item
End Sub
Private Sub myAppItem_PropertyChange(ByVal Name As String)
If Name = "Subject" Then
MsgBox "yes"
End If
End Sub- Hide quoted text -
- Show quoted text -
Matt
2009-07-09 15:20:46 UTC
Permalink
Post by Matt
I am just learning Outlook VBA and am trying to get the
hang of different objects and methods. I am running Outlook 2003
w/ Exchange
What I'm trying to do is flag an appointment when
the subject changes. (As you said, i had to change the subject
twice to fire the propertychange event, thanks).
Thanks,
Matt
Post by Sue Mosher [MVP]
The item has already changed before your code instantiates the myAppItem
object. Only if you change it a second time will you get that event.
Maybe you should start at the beginning and explain what you're trying to
do, in what version of Outlook.
--
Sue Mosher, Outlook MVP
     Jumpstart for Power Users and Administrators
   http://www.outlookcode.com/article.aspx?id=54
Post by Matt
I am trying to get the PropertyChange event to fire using MS Outlook
2003...
but for some reason it doesn't. Thought I could just set the variable
to the
AppointmentItem and use the WithEvents.
Any help is appreciated. Thanks, Matt (code below)
Option Explicit
Private WithEvents olDeletedItems As Items
Private WithEvents myOlItems As Items
Public WithEvents myAppItem As Outlook.AppointmentItem
Private Sub Application_Startup()
  Dim objNS As NameSpace
   Set objNS = Application.GetNamespace("MAPI")
   Set olDeletedItems = objNS.GetDefaultFolder
(olFolderDeletedItems).Items
 Set myOlItems = objNS.GetDefaultFolder(olFolderCalendar).Items
   Set objNS = Nothing
    End Sub
Private Sub Application_Quit()
 Set olDeletedItems = Nothing
 End Sub
Private Sub olDeletedItems_ItemAdd(ByVal Item As Object)
 If InStr(1, Item.Subject, "Vacation") Then
 MsgBox Item.Subject
 End If
   Set Item = Nothing
End Sub
Private Sub myOlItems_ItemChange(ByVal Item As Object)
Set myAppItem = Item
End Sub
Private Sub myAppItem_PropertyChange(ByVal Name As String)
If Name = "Subject" Then
MsgBox "yes"
End If
End Sub- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -
Figured out a way to capture the appointment event the first
time through by using the Items_Open and setting the appointment
item to the ActiveInspector().CurrentItem..Here's the code

Private Sub myOlItems_Open(Cancel As Boolean)
Set myAppItem = OutlookApplication.ActiveInspector().CurrentItem
End Sub
Matt
2009-07-09 15:27:57 UTC
Permalink
Post by Matt
Post by Matt
I am just learning Outlook VBA and am trying to get the
hang of different objects and methods. I am running Outlook 2003
w/ Exchange
What I'm trying to do is flag an appointment when
the subject changes. (As you said, i had to change the subject
twice to fire the propertychange event, thanks).
Thanks,
Matt
Post by Sue Mosher [MVP]
The item has already changed before your code instantiates the myAppItem
object. Only if you change it a second time will you get that event.
Maybe you should start at the beginning and explain what you're trying to
do, in what version of Outlook.
--
Sue Mosher, Outlook MVP
     Jumpstart for Power Users and Administrators
   http://www.outlookcode.com/article.aspx?id=54
Post by Matt
I am trying to get the PropertyChange event to fire using MS Outlook
2003...
but for some reason it doesn't. Thought I could just set the variable
to the
AppointmentItem and use the WithEvents.
Any help is appreciated. Thanks, Matt (code below)
Option Explicit
Private WithEvents olDeletedItems As Items
Private WithEvents myOlItems As Items
Public WithEvents myAppItem As Outlook.AppointmentItem
Private Sub Application_Startup()
  Dim objNS As NameSpace
   Set objNS = Application.GetNamespace("MAPI")
   Set olDeletedItems = objNS.GetDefaultFolder
(olFolderDeletedItems).Items
 Set myOlItems = objNS.GetDefaultFolder(olFolderCalendar).Items
   Set objNS = Nothing
    End Sub
Private Sub Application_Quit()
 Set olDeletedItems = Nothing
 End Sub
Private Sub olDeletedItems_ItemAdd(ByVal Item As Object)
 If InStr(1, Item.Subject, "Vacation") Then
 MsgBox Item.Subject
 End If
   Set Item = Nothing
End Sub
Private Sub myOlItems_ItemChange(ByVal Item As Object)
Set myAppItem = Item
End Sub
Private Sub myAppItem_PropertyChange(ByVal Name As String)
If Name = "Subject" Then
MsgBox "yes"
End If
End Sub- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -
Figured out a way to capture the appointment event the first
time through by using the Items_Open and setting the appointment
item to the ActiveInspector().CurrentItem..Here's the code
Private Sub myOlItems_Open(Cancel As Boolean)
Set myAppItem = OutlookApplication.ActiveInspector().CurrentItem
End Sub- Hide quoted text -
- Show quoted text -
Ok..I've been a VBA programmer for a while but still
fairly new to the Outlook VBA world...I can see that
my code to handle this event is a little ubiquitous
but it will have to do for now. Thanks again. Will
check out those links.
Matt
2009-07-09 16:01:36 UTC
Permalink
Post by Matt
Post by Matt
Post by Matt
I am just learning Outlook VBA and am trying to get the
hang of different objects and methods. I am running Outlook 2003
w/ Exchange
What I'm trying to do is flag an appointment when
the subject changes. (As you said, i had to change the subject
twice to fire the propertychange event, thanks).
Thanks,
Matt
Post by Sue Mosher [MVP]
The item has already changed before your code instantiates the myAppItem
object. Only if you change it a second time will you get that event.
Maybe you should start at the beginning and explain what you're trying to
do, in what version of Outlook.
--
Sue Mosher, Outlook MVP
     Jumpstart for Power Users and Administrators
   http://www.outlookcode.com/article.aspx?id=54
Post by Matt
I am trying to get the PropertyChange event to fire using MS Outlook
2003...
but for some reason it doesn't. Thought I could just set the variable
to the
AppointmentItem and use the WithEvents.
Any help is appreciated. Thanks, Matt (code below)
Option Explicit
Private WithEvents olDeletedItems As Items
Private WithEvents myOlItems As Items
Public WithEvents myAppItem As Outlook.AppointmentItem
Private Sub Application_Startup()
  Dim objNS As NameSpace
   Set objNS = Application.GetNamespace("MAPI")
   Set olDeletedItems = objNS.GetDefaultFolder
(olFolderDeletedItems).Items
 Set myOlItems = objNS.GetDefaultFolder(olFolderCalendar).Items
   Set objNS = Nothing
    End Sub
Private Sub Application_Quit()
 Set olDeletedItems = Nothing
 End Sub
Private Sub olDeletedItems_ItemAdd(ByVal Item As Object)
 If InStr(1, Item.Subject, "Vacation") Then
 MsgBox Item.Subject
 End If
   Set Item = Nothing
End Sub
Private Sub myOlItems_ItemChange(ByVal Item As Object)
Set myAppItem = Item
End Sub
Private Sub myAppItem_PropertyChange(ByVal Name As String)
If Name = "Subject" Then
MsgBox "yes"
End If
End Sub- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -
Figured out a way to capture the appointment event the first
time through by using the Items_Open and setting the appointment
item to the ActiveInspector().CurrentItem..Here's the code
Private Sub myOlItems_Open(Cancel As Boolean)
Set myAppItem = OutlookApplication.ActiveInspector().CurrentItem
End Sub- Hide quoted text -
- Show quoted text -
Ok..I've been a VBA programmer for a while but still
fairly new to the Outlook VBA world...I can see that
my code to handle this event is a little ubiquitous
but it will have to do for now. Thanks again. Will
check out those links.- Hide quoted text -
- Show quoted text -
Sue, Spoke to soon that doesn't work...Uable to capture the Items_Open
event.
Thought that opening an item would trigger that event but I guess
not..Looks like there is no
Items_Open method just an Item_Open method. Ok back to the drawing
board. I will certainly look at those links now.

Sue Mosher [MVP]
2009-07-09 15:51:18 UTC
Permalink
The Items object has no Open event, so I'm not sure what you're
accomplishing there. Also, Application.ActiveInspector.CurrentItem returns
only the item window currently visible or most recently accessed. It doesn't
help you if (a) multiple appointments are open (that's where you need a
wrapper class) and thus available for the user to change or (b) the user
edits the subject right in the Calendar window.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Matt" <***@yahoo.com> wrote in message news:0d790108-56f8-439e-b480-***@24g2000yqm.googlegroups.com...

Figured out a way to capture the appointment event the first
time through by using the Items_Open and setting the appointment
item to the ActiveInspector().CurrentItem..Here's the code

Private Sub myOlItems_Open(Cancel As Boolean)
Set myAppItem = OutlookApplication.ActiveInspector().CurrentItem
End Sub
Post by Matt
I am just learning Outlook VBA and am trying to get the
hang of different objects and methods. I am running Outlook 2003
w/ Exchange
What I'm trying to do is flag an appointment when
the subject changes. (As you said, i had to change the subject
twice to fire the propertychange event, thanks).
Thanks,
Matt
Post by Sue Mosher [MVP]
The item has already changed before your code instantiates the myAppItem
object. Only if you change it a second time will you get that event.
Post by Matt
I am trying to get the PropertyChange event to fire using MS Outlook
2003...
but for some reason it doesn't. Thought I could just set the variable
to the
AppointmentItem and use the WithEvents.
Any help is appreciated. Thanks, Matt (code below)
Option Explicit
Private WithEvents olDeletedItems As Items
Private WithEvents myOlItems As Items
Public WithEvents myAppItem As Outlook.AppointmentItem
Private Sub Application_Startup()
Dim objNS As NameSpace
Set objNS = Application.GetNamespace("MAPI")
Set olDeletedItems = objNS.GetDefaultFolder
(olFolderDeletedItems).Items
Set myOlItems = objNS.GetDefaultFolder(olFolderCalendar).Items
Set objNS = Nothing
End Sub
Private Sub Application_Quit()
Set olDeletedItems = Nothing
End Sub
Private Sub olDeletedItems_ItemAdd(ByVal Item As Object)
If InStr(1, Item.Subject, "Vacation") Then
MsgBox Item.Subject
End If
Set Item = Nothing
End Sub
Private Sub myOlItems_ItemChange(ByVal Item As Object)
Set myAppItem = Item
End Sub
Private Sub myAppItem_PropertyChange(ByVal Name As String)
If Name = "Subject" Then
MsgBox "yes"
End If
End Sub- Hide quoted text -
- Show quoted text -- Hide quoted text -
- Show quoted text -
Loading...