|
|
|
date: Tue, 15 Jul 2008 10:17:21 -0700 (PDT),
group: microsoft.public.office.developer.outlook.vba
back
RE: identifying conflicts
In the discussion thread that Stephen indicated, the 2nd page of posts covers
your scenario, where you don't need to know the details of the conflicting
appointments, only whether a conflict exists. For that, you'd use the
Recipient.FreeBusy method.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx
"TroutUSA" wrote:
> I have created code that adds appointments to my calendar from a text
> document. The text document contains 7 to 10 rolling schedule
> information. (New information as well as old information.)
> I've parsed the text to create appointments, but I'm having trouble
> preventing duplicate appointments from being entered.
> Here is some of the code I'm using:
> Set oAppnt = Application.CreateItem(olAppointmentItem)
> With oAppnt
> .Start = (strWorkDate + " " + strStartTime)
> .End = (strWorkDate + " " + strStopTime)
> .BusyStatus = olBusy
> .Subject = strWorkCode
> End With
> ' oAppnt.Save
> If oAppnt.Conflicts.Count > 0 Then
> For Each con In oAppnt.Conflicts
> If con.Parent.Subject = oAppnt.Subject And
> con.Parent.Start & _
> = oAppnt.Start Then
> bolAppointmentExists = True
> Exit For
> End If
> Next
> End If
>
> oAppt.Conflicts.Count always = 0. Even though there is an existing
> appointment with the exaact same date, start and end times???
>
> Any help willbe greatly appreciated!
>
date: Tue, 15 Jul 2008 12:53:03 -0700
author: Sue Mosher [MVP-Outlook]
Re: identifying conflicts
On Jul 15, 3:53 pm, Sue Mosher [MVP-Outlook]
wrote:
> In the discussion thread that Stephen indicated, the 2nd page of posts covers
> your scenario, where you don't need to know the details of the conflicting
> appointments, only whether a conflict exists. For that, you'd use the
> Recipient.FreeBusy method.
> --
> Sue Mosher, Outlook MVP
> Author of Microsoft Outlook Programming: Jumpstart
> for Administrators, Power Users, and Developers
> http://www.outlookcode.com/jumpstart.aspx
>
>
>
> "TroutUSA" wrote:
> > I have created code that adds appointments to my calendar from a text
> > document. The text document contains 7 to 10 rolling schedule
> > information. (New information as well as old information.)
> > I've parsed the text to create appointments, but I'm having trouble
> > preventing duplicate appointments from being entered.
> > Here is some of the code I'm using:
> > Set oAppnt = Application.CreateItem(olAppointmentItem)
> > With oAppnt
> > .Start = (strWorkDate " " strStartTime)
> > .End = (strWorkDate " " strStopTime)
> > .BusyStatus = olBusy
> > .Subject = strWorkCode
> > End With
> > ' oAppnt.Save
> > If oAppnt.Conflicts.Count > 0 Then
> > For Each con In oAppnt.Conflicts
> > If con.Parent.Subject = oAppnt.Subject And
> > con.Parent.Start & _
> > = oAppnt.Start Then
> > bolAppointmentExists = True
> > Exit For
> > End If
> > Next
> > End If
>
> > oAppt.Conflicts.Count always = 0. Even though there is an existing
> > appointment with the exaact same date, start and end times???
>
> > Any help willbe greatly appreciated!- Hide quoted text -
>
> - Show quoted text -
Thank you Sue. I actually came across the discussion you linked to,
but my case doesn't involve any recipients...just me. (I was also
unaware that my concept of conflicts was off.)
If I change code from the discussion to:
oCalFolder = oNS.Outlook.OlDefaultFolders.olFolderCalendar
sCalendarFilter = "[Start] < """ & Format(dtApptEnd, "M/dd/yyyy hh:mm
tt") & _
""" AND [End] > """ & Format(dtApptStart, "M/dd/yyyy hh:mm tt") &
"""" '& _
oOLTbl = oCalFolder.GetTable(sCalendarFilter)
If Not oOLTbl.EndOfTable Then
bHasConflict = True
End If
I should be in the right ballpark?
Thanks much for your helpful comments!
date: Wed, 16 Jul 2008 07:32:53 -0700 (PDT)
author: TroutUSA
Re: identifying conflicts
Not quite. The method used to return one of your own default folders is
Namespace.GetDefaultFolder. Also, I'd use the Folder.Items.Find method to
look for the conflict, because all you need to know is whether the item
exists. That method will either return an AppointmentItem or Nothing. The
search filter search looks OK, though.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx
"TroutUSA" wrote:
>
> Thank you Sue. I actually came across the discussion you linked to,
> but my case doesn't involve any recipients...just me. (I was also
> unaware that my concept of conflicts was off.)
>
> If I change code from the discussion to:
>
> oCalFolder = oNS.Outlook.OlDefaultFolders.olFolderCalendar
> sCalendarFilter = "[Start] < """ & Format(dtApptEnd, "M/dd/yyyy hh:mm
> tt") & _
> """ AND [End] > """ & Format(dtApptStart, "M/dd/yyyy hh:mm tt") &
> """" '& _
> oOLTbl = oCalFolder.GetTable(sCalendarFilter)
> If Not oOLTbl.EndOfTable Then
> bHasConflict = True
> End If
>
>
> I should be in the right ballpark?
date: Wed, 16 Jul 2008 08:06:10 -0700
author: Sue Mosher [MVP-Outlook]
Re: identifying conflicts
On Jul 16, 11:06 am, Sue Mosher [MVP-Outlook]
wrote:
> Not quite. The method used to return one of your own default folders is
> Namespace.GetDefaultFolder. Also, I'd use the Folder.Items.Find method to
> look for the conflict, because all you need to know is whether the item
> exists. That method will either return an AppointmentItem or Nothing. The
> search filter search looks OK, though.
> --
> Sue Mosher, Outlook MVP
> Author of Microsoft Outlook Programming: Jumpstart
> for Administrators, Power Users, and Developers
> http://www.outlookcode.com/jumpstart.aspx
>
>
>
> "TroutUSA" wrote:
>
> > Thank you Sue. I actually came across the discussion you linked to,
> > but my case doesn't involve any recipients...just me. (I was also
> > unaware that my concept of conflicts was off.)
>
> > If I change code from the discussion to:
>
> > oCalFolder = oNS.Outlook.OlDefaultFolders.olFolderCalendar
> > sCalendarFilter = "[Start] < """ & Format(dtApptEnd, "M/dd/yyyy hh:mm
> > tt") & _
> > """ AND [End] > """ & Format(dtApptStart, "M/dd/yyyy hh:mm tt")> > """" '& _
> > oOLTbl = oCalFolder.GetTable(sCalendarFilter)
> > If Not oOLTbl.EndOfTable Then
> > bHasConflict = True
> > End If
>
> > I should be in the right ballpark?- Hide quoted text -
>
> - Show quoted text -
Thanks again.
I had to change the filter as follows:
sCalendarFilter = "[Start] = #" & Format(oAppnt.Start, "mm/dd/yyyy
hh:mm:ss") & _
"# AND [End] = #" & Format(oAppnt.End, "mm/dd/yyyy
hh:mm:ss") & "#"
then I added:
Set oConflictAppnt =
oCalFolder.Items.Find(sCalendarFilter)
If oConflictAppnt = Nothing Then
oAppnt.Save
End If
I get an error message "Invalid Use of Object" and the "Nothing" is
highlighted. This is strange because the VBE indicates that
"oConflictAppnt = Nothing" when I hover over the variable while
stepping through the code.
date: Wed, 16 Jul 2008 10:10:18 -0700 (PDT)
author: TroutUSA
Re: identifying conflicts
To handle the possibility of no conflict, you need to add an On Error Resume
Next statement before that code. Once you do that, you can use:
If oConflictAppnt Is Nothing Then
etc. You also need to change your filter back to the way it was. The dates
must be expressed as strings, not date/time values. See
http://www.outlookcode.com/article.aspx?id=30
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx
"TroutUSA" wrote:
> On Jul 16, 11:06 am, Sue Mosher [MVP-Outlook]
> wrote:
> > Not quite. The method used to return one of your own default folders is
> > Namespace.GetDefaultFolder. Also, I'd use the Folder.Items.Find method to
> > look for the conflict, because all you need to know is whether the item
> > exists. That method will either return an AppointmentItem or Nothing. The
> > search filter search looks OK, though.
> >
> > "TroutUSA" wrote:
> >
> > > Thank you Sue. I actually came across the discussion you linked to,
> > > but my case doesn't involve any recipients...just me. (I was also
> > > unaware that my concept of conflicts was off.)
> >
> > > If I change code from the discussion to:
> >
> > > oCalFolder = oNS.Outlook.OlDefaultFolders.olFolderCalendar
> > > sCalendarFilter = "[Start] < """ & Format(dtApptEnd, "M/dd/yyyy hh:mm
> > > tt") & _
> > > """ AND [End] > """ & Format(dtApptStart, "M/dd/yyyy hh:mm tt") &
> > > """" '& _
> > > oOLTbl = oCalFolder.GetTable(sCalendarFilter)
> > > If Not oOLTbl.EndOfTable Then
> > > bHasConflict = True
> > > End If
> >
> > > I should be in the right ballpark?- Hide quoted text -
> >
> > - Show quoted text -
>
> Thanks again.
>
> I had to change the filter as follows:
>
> sCalendarFilter = "[Start] = #" & Format(oAppnt.Start, "mm/dd/yyyy
> hh:mm:ss") & _
> "# AND [End] = #" & Format(oAppnt.End, "mm/dd/yyyy
> hh:mm:ss") & "#"
>
> then I added:
>
> Set oConflictAppnt =
> oCalFolder.Items.Find(sCalendarFilter)
> If oConflictAppnt = Nothing Then
> oAppnt.Save
> End If
>
> I get an error message "Invalid Use of Object" and the "Nothing" is
> highlighted. This is strange because the VBE indicates that
> "oConflictAppnt = Nothing" when I hover over the variable while
> stepping through the code.
>
date: Wed, 16 Jul 2008 10:27:01 -0700
author: Sue Mosher [MVP-Outlook]
Re: identifying conflicts
On Jul 16, 1:27 pm, Sue Mosher [MVP-Outlook]
wrote:
> To handle the possibility of no conflict, you need to add an On Error Resume
> Next statement before that code. Once you do that, you can use:
>
> If oConflictAppnt Is Nothing Then
>
> etc. You also need to change your filter back to the way it was. The dates
> must be expressed as strings, not date/time values. Seehttp://www.outlookcode.com/article.aspx?id=30
> --
> Sue Mosher, Outlook MVP
> Author of Microsoft Outlook Programming: Jumpstart
> for Administrators, Power Users, and Developers
> http://www.outlookcode.com/jumpstart.aspx
>
>
>
> "TroutUSA" wrote:
> > On Jul 16, 11:06 am, Sue Mosher [MVP-Outlook]
> > wrote:
> > > Not quite. The method used to return one of your own default folders is
> > > Namespace.GetDefaultFolder. Also, I'd use the Folder.Items.Find method to
> > > look for the conflict, because all you need to know is whether the item
> > > exists. That method will either return an AppointmentItem or Nothing. The
> > > search filter search looks OK, though.
>
> > > "TroutUSA" wrote:
>
> > > > Thank you Sue. I actually came across the discussion you linked to,
> > > > but my case doesn't involve any recipients...just me. (I was also
> > > > unaware that my concept of conflicts was off.)
>
> > > > If I change code from the discussion to:
>
> > > > oCalFolder = oNS.Outlook.OlDefaultFolders.olFolderCalendar
> > > > sCalendarFilter = "[Start] < """ & Format(dtApptEnd, "M/dd/yyyy hh:mm
> > > > tt") & _
> > > > """ AND [End] > """ & Format(dtApptStart, "M/dd/yyyy hh:mm tt") &
> > > > """" '& _
> > > > oOLTbl = oCalFolder.GetTable(sCalendarFilter)
> > > > If Not oOLTbl.EndOfTable Then
> > > > bHasConflict = True
> > > > End If
>
> > > > I should be in the right ballpark?- Hide quoted text -
>
> > > - Show quoted text -
>
> > Thanks again.
>
> > I had to change the filter as follows:
>
> > sCalendarFilter = "[Start] = #" & Format(oAppnt.Start, "mm/dd/yyyy
> > hh:mm:ss") & _
> > "# AND [End] = #" & Format(oAppnt.End, "mm/dd/yyyy
> > hh:mm:ss") & "#"
>
> > then I added:
>
> > Set oConflictAppnt =
> > oCalFolder.Items.Find(sCalendarFilter)
> > If oConflictAppnt = Nothing Then
> > oAppnt.Save
> > End If
>
> > I get an error message "Invalid Use of Object" and the "Nothing" is
> > highlighted. This is strange because the VBE indicates that
> > "oConflictAppnt = Nothing" when I hover over the variable while
> > stepping through the code.- Hide quoted text -
>
> - Show quoted text -
This link really helped me out:
http://www.outlookcode.com/article.aspx?id=30
I had the format of the date all wrong. Also, there has to be
quotation marks in the string. The function:
Quote(myText)
helped me to properly format the filter string.
My finished code (which identified existing appointments) is:
Set oAppnt = Application.CreateItem(olAppointmentItem)
With oAppnt
.Start = (strWorkDate " " strStartTime)
.End = (strWorkDate " " strStopTime)
.BusyStatus = olBusy
.Subject = strWorkCode
End With
'save only if there are no existing duplicate
appointment
On Error Resume Next
sCalendarFilter = "[Start] = " &
Quote(Format(oAppnt.Start, "mmmm dd, yyyy hh:mm AMPM")) & _
" AND [End] = " & Quote(Format(oAppnt.End, "mmmm dd,
yyyy hh:mm AMPM"))
Set oConflictAppnt =
oCalFolder.Items.Find(sCalendarFilter)
If oConflictAppnt Is Nothing Then
oAppnt.Save
End If
On Error GoTo Error_Start
By changing the "=" to ">=" or "<=" in sCalendarFilter I could locate
conflicting (overlapping) appointments instead of just preventing the
entry of duplicate appointments.
Thanks much for your help. I would never had figured out the filter
format without the link you provided.
date: Wed, 16 Jul 2008 17:30:40 -0700 (PDT)
author: TroutUSA
|
|