Home All Groups Group Topic Archive Search About

PropertyChange event not working

Author
8 Jul 2009 11:00 PM
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

Author
9 Jul 2009 3:58 AM
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
   Author of Microsoft Outlook 2007 Programming:
     Jumpstart for Power Users and Administrators
    http://www.outlookcode.com/article.aspx?id=54


Show quoteHide quote
"Matt" <Matthew_Som***@yahoo.com> wrote in message
news:ec155405-a277-4c92-b69b-62a44ecc0bb0@26g2000yqk.googlegroups.com...
>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
>
Are all your drivers up to date? click for free checkup

Author
9 Jul 2009 1:53 PM
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


Show quoteHide quote
On Jul 8, 11:58 pm, "Sue Mosher [MVP]" <sue***@turtleflock.com> wrote:
> 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
>
> "Matt" <Matthew_Som***@yahoo.com> wrote in message
>
> news:ec155405-a277-4c92-b69b-62a44ecc0bb0@26g2000yqk.googlegroups.com...
>
>
>
> >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 -
Author
9 Jul 2009 2:48 PM
Sue Mosher [MVP]
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" <Matthew_Som***@yahoo.com> wrote in message
news:2b83303d-e452-47c5-b218-54e470cd2ea2@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


Show quoteHide quote
On Jul 8, 11:58 pm, "Sue Mosher [MVP]" <sue***@turtleflock.com> wrote:
> 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.

> "Matt" <Matthew_Som***@yahoo.com> wrote in message
>
> news:ec155405-a277-4c92-b69b-62a44ecc0bb0@26g2000yqk.googlegroups.com...
>
>
>
> >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 -
Author
9 Jul 2009 3:20 PM
Matt
On Jul 9, 9:53 am, Matt <Matthew_Som***@yahoo.com> wrote:
Show quoteHide quote
> 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
>
> On Jul 8, 11:58 pm, "Sue Mosher [MVP]" <sue***@turtleflock.com> wrote:
>
>
>
> > 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
>
> > "Matt" <Matthew_Som***@yahoo.com> wrote in message
>
> >news:ec155405-a277-4c92-b69b-62a44ecc0bb0@26g2000yqk.googlegroups.com...
>
> > >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
Author
9 Jul 2009 3:27 PM
Matt
On Jul 9, 11:20 am, Matt <Matthew_Som***@yahoo.com> wrote:
Show quoteHide quote
> On Jul 9, 9:53 am, Matt <Matthew_Som***@yahoo.com> wrote:
>
>
>
>
>
> > 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
>
> > On Jul 8, 11:58 pm, "Sue Mosher [MVP]" <sue***@turtleflock.com> wrote:
>
> > > 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
>
> > > "Matt" <Matthew_Som***@yahoo.com> wrote in message
>
> > >news:ec155405-a277-4c92-b69b-62a44ecc0bb0@26g2000yqk.googlegroups.com....
>
> > > >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.
Author
9 Jul 2009 4:01 PM
Matt
On Jul 9, 11:27 am, Matt <Matthew_Som***@yahoo.com> wrote:
Show quoteHide quote
> On Jul 9, 11:20 am, Matt <Matthew_Som***@yahoo.com> wrote:
>
>
>
>
>
> > On Jul 9, 9:53 am, Matt <Matthew_Som***@yahoo.com> wrote:
>
> > > 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
>
> > > On Jul 8, 11:58 pm, "Sue Mosher [MVP]" <sue***@turtleflock.com> wrote:
>
> > > > 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
>
> > > > "Matt" <Matthew_Som***@yahoo.com> wrote in message
>
> > > >news:ec155405-a277-4c92-b69b-62a44ecc0bb0@26g2000yqk.googlegroups.com...
>
> > > > >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.
Author
9 Jul 2009 3:51 PM
Sue Mosher [MVP]
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" <Matthew_Som***@yahoo.com> wrote in message
news:0d790108-56f8-439e-b480-19cf9e18a0cb@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

On Jul 9, 9:53 am, Matt <Matthew_Som***@yahoo.com> wrote:
Show quoteHide quote
> 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
>
> On Jul 8, 11:58 pm, "Sue Mosher [MVP]" <sue***@turtleflock.com> wrote:
>
>
>
> > 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.
>
> > "Matt" <Matthew_Som***@yahoo.com> wrote in message
>
> >news:ec155405-a277-4c92-b69b-62a44ecc0bb0@26g2000yqk.googlegroups.com...
>
> > >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 -

Bookmark and Share