PC Review
Forums
Newsgroups
Microsoft Outlook
Microsoft Outlook VBA Programming
Adding an entry to a Calendar in a shared public folder with VBA
Forums
Newsgroups
Microsoft Outlook
Microsoft Outlook VBA Programming
Adding an entry to a Calendar in a shared public folder with VBA
![]() |
Adding an entry to a Calendar in a shared public folder with VBA |
|
|
Thread Tools | Rate Thread |
|
|
#1 |
|
Guest
Posts: n/a
|
I have a web application that stores vacation requests in
an Access database. I would like to extend its functionality by adding a macro to the Access DB that would add the requests to a "Vacation Calander" (alias: "VacationCalendar") in a shared public folder in Outlook. A subroutine that should do this is listed below. It works great if the Calendar used is an individual user's calendar. However, the following line produces a "The server mailbox cannot be opened because this address book entry is not an e-mail user" error message, when the "Vacation Calander" (alias: "VacationCalendar") in a shared public folder in used. Set objFolder = _ objNS.GetSharedDefaultFolder(objRecip, _ 9) 'olFolderCalendar The public folder has e-mail access enabled and appears in the Outlook global address list. Any insight would be appreciated. Thanks in advance. Keith ================== Sub CreateOtherUserAppointment() Dim objApp As Outlook.Application Dim objNS 'As Outlook.NameSpace Dim objFolder 'As Outlook.MAPIFolder Dim objDummy 'As Outlook.MailItem Dim objRecip 'As Outlook.Recipient Dim objAppt 'As Outlook.AppointmentItem Dim strMsg 'As String Dim strName 'As String On Error Resume Next ' ### name of Calendar to use ### strName = "VacationCalendar" Set objApp = New Outlook.Application Set objNS = objApp.GetNamespace("MAPI") Set objDummy = objApp.CreateItem(0) 'olMailItem Set objRecip = objDummy.Recipients.Add(strName) objRecip.Resolve If Not objRecip.Resolve Then myItem.Display If objRecip.Resolved Then On Error Resume Next Set objFolder = _ objNS.GetSharedDefaultFolder(objRecip, _ 9) 'olFolderCalendar If Not objFolder Is Nothing Then Set objAppt = objFolder.Items.Add If Not objAppt Is Nothing Then With objAppt .Subject = "Test Appointment" .Start = #4/21/2004 8:00:00 AM# .End = #4/21/2004 4:00:00 PM# .Location = Town & Gown .BusyStatus = 1 .Body = "Stop the insanity.... " .AllDayEvent = False .Save End With End If End If Else MsgBox "Could not find " & Chr(34) & strName & Chr (34), , _ "User not found" End If Set objApp = Nothing Set objNS = Nothing Set objFolder = Nothing Set objDummy = Nothing Set objRecip = Nothing Set objAppt = Nothing End Sub ================== |
|
|
|
#2 |
|
Guest
Posts: n/a
|
The message means exactly what it says: You can't use that method to get to
a public folder. It works only on default mailbox folders. To get a folder in Public Folders, you need to walk the folder hierarchy using the Folders collections or use a function that does that for you. See http://www.outlookcode.com/d/code/getfolder.htm -- Sue Mosher, Outlook MVP Author of Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx "Keith E." <kengelhardt@designforum.com> wrote in message news:44f601c42b99$1fe5efd0$a001280a@phx.gbl... > I have a web application that stores vacation requests in > an Access database. > I would like to extend its functionality by adding a macro > to the Access DB that > would add the requests to a "Vacation Calander" > (alias: "VacationCalendar") > in a shared public folder in Outlook. > > A subroutine that should do this is listed below. It works > great if the Calendar used > is an individual user's calendar. However, the following > line produces a "The server mailbox > cannot be opened because this address book entry is not an > e-mail user" error message, when the > "Vacation Calander" (alias: "VacationCalendar") in a > shared public folder in used. > > > Set objFolder = _ > objNS.GetSharedDefaultFolder(objRecip, _ > 9) 'olFolderCalendar > > > The public folder has e-mail access enabled and appears in > the Outlook global address list. > > Any insight would be appreciated. > > Thanks in advance. > > Keith > > > > > > > > ================== > Sub CreateOtherUserAppointment() > Dim objApp As Outlook.Application > Dim objNS 'As Outlook.NameSpace > Dim objFolder 'As Outlook.MAPIFolder > Dim objDummy 'As Outlook.MailItem > Dim objRecip 'As Outlook.Recipient > Dim objAppt 'As Outlook.AppointmentItem > Dim strMsg 'As String > Dim strName 'As String > On Error Resume Next > > ' ### name of Calendar to use ### > strName = "VacationCalendar" > > Set objApp = New Outlook.Application > Set objNS = objApp.GetNamespace("MAPI") > Set objDummy = objApp.CreateItem(0) 'olMailItem > > Set objRecip = objDummy.Recipients.Add(strName) > objRecip.Resolve > If Not objRecip.Resolve Then myItem.Display > If objRecip.Resolved Then > > On Error Resume Next > Set objFolder = _ > objNS.GetSharedDefaultFolder(objRecip, _ > 9) 'olFolderCalendar > If Not objFolder Is Nothing Then > Set objAppt = objFolder.Items.Add > If Not objAppt Is Nothing Then > With objAppt > .Subject = "Test Appointment" > .Start = #4/21/2004 8:00:00 AM# > .End = #4/21/2004 4:00:00 PM# > .Location = Town & Gown > .BusyStatus = 1 > .Body = "Stop the insanity.... " > .AllDayEvent = False > .Save > End With > End If > End If > Else > MsgBox "Could not find " & Chr(34) & strName & Chr > (34), , _ > "User not found" > End If > > Set objApp = Nothing > Set objNS = Nothing > Set objFolder = Nothing > Set objDummy = Nothing > Set objRecip = Nothing > Set objAppt = Nothing > End Sub > ================== > |
|
|
|
#3 |
|
Guest
Posts: n/a
|
Thanks for the tip. By Setting a reference to an Exchange
Public Folder (http://www.fabalou.com/Outlook/GetOutlookFolder.asp), I was able to post a appointment to the calendar. Any idea how I would remove the appointment from the calendar via code, if a user cancels the vacation? Keith E. >-----Original Message----- >The message means exactly what it says: You can't use that method to get to >a public folder. It works only on default mailbox folders. > >To get a folder in Public Folders, you need to walk the folder hierarchy >using the Folders collections or use a function that does that for you. See >http://www.outlookcode.com/d/code/getfolder.htm > >-- >Sue Mosher, Outlook MVP >Author of > Microsoft Outlook Programming - Jumpstart for > Administrators, Power Users, and Developers > http://www.outlookcode.com/jumpstart.aspx > > >"Keith E." <kengelhardt@designforum.com> wrote in message >news:44f601c42b99$1fe5efd0$a001280a@phx.gbl... >> I have a web application that stores vacation requests in >> an Access database. >> I would like to extend its functionality by adding a macro >> to the Access DB that >> would add the requests to a "Vacation Calander" >> (alias: "VacationCalendar") >> in a shared public folder in Outlook. >> >> A subroutine that should do this is listed below. It works >> great if the Calendar used >> is an individual user's calendar. However, the following >> line produces a "The server mailbox >> cannot be opened because this address book entry is not an >> e-mail user" error message, when the >> "Vacation Calander" (alias: "VacationCalendar") in a >> shared public folder in used. >> >> >> Set objFolder = _ >> objNS.GetSharedDefaultFolder(objRecip, _ >> 9) 'olFolderCalendar >> >> >> The public folder has e-mail access enabled and appears in >> the Outlook global address list. >> >> Any insight would be appreciated. >> >> Thanks in advance. >> >> Keith >> >> >> >> >> >> >> >> ================== >> Sub CreateOtherUserAppointment() >> Dim objApp As Outlook.Application >> Dim objNS 'As Outlook.NameSpace >> Dim objFolder 'As Outlook.MAPIFolder >> Dim objDummy 'As Outlook.MailItem >> Dim objRecip 'As Outlook.Recipient >> Dim objAppt 'As Outlook.AppointmentItem >> Dim strMsg 'As String >> Dim strName 'As String >> On Error Resume Next >> >> ' ### name of Calendar to use ### >> strName = "VacationCalendar" >> >> Set objApp = New Outlook.Application >> Set objNS = objApp.GetNamespace("MAPI") >> Set objDummy = objApp.CreateItem(0) 'olMailItem >> >> Set objRecip = objDummy.Recipients.Add(strName) >> objRecip.Resolve >> If Not objRecip.Resolve Then myItem.Display >> If objRecip.Resolved Then >> >> On Error Resume Next >> Set objFolder = _ >> objNS.GetSharedDefaultFolder(objRecip, _ >> 9) 'olFolderCalendar >> If Not objFolder Is Nothing Then >> Set objAppt = objFolder.Items.Add >> If Not objAppt Is Nothing Then >> With objAppt >> .Subject = "Test Appointment" >> .Start = #4/21/2004 8:00:00 AM# >> .End = #4/21/2004 4:00:00 PM# >> .Location = Town & Gown >> .BusyStatus = 1 >> .Body = "Stop the insanity.... " >> .AllDayEvent = False >> .Save >> End With >> End If >> End If >> Else >> MsgBox "Could not find " & Chr(34) & strName & Chr >> (34), , _ >> "User not found" >> End If >> >> Set objApp = Nothing >> Set objNS = Nothing >> Set objFolder = Nothing >> Set objDummy = Nothing >> Set objRecip = Nothing >> Set objAppt = Nothing >> End Sub >> ================== >> > > >. > |
|
|
|
#4 |
|
Guest
Posts: n/a
|
The real question is, "How would I find the appointment that the user wants
to cancel?" To answer that you'll have to go back to the business logic of your application and decide how you want the user to indicate that they want to cancel a vacation. Once you've figured that out, you should know what information you'll have available to look up the appointment. Once you have an AppointmentItem object, you can use the Delete method to remove it. -- Sue Mosher, Outlook MVP Author of Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx "Keith E." <kengelhardt@designforum.com> wrote in message news:468201c42bcf$d646b800$a601280a@phx.gbl... > Thanks for the tip. By Setting a reference to an Exchange > Public Folder > (http://www.fabalou.com/Outlook/GetOutlookFolder.asp), I > was able to post a appointment to the calendar. > > Any idea how I would remove the appointment from the > calendar via code, if a user cancels the vacation? > > Keith E. > > >-----Original Message----- > >The message means exactly what it says: You can't use > that method to get to > >a public folder. It works only on default mailbox folders. > > > >To get a folder in Public Folders, you need to walk the > folder hierarchy > >using the Folders collections or use a function that does > that for you. See > >http://www.outlookcode.com/d/code/getfolder.htm > > > > > >"Keith E." <kengelhardt@designforum.com> wrote in message > >news:44f601c42b99$1fe5efd0$a001280a@phx.gbl... > >> I have a web application that stores vacation requests > in > >> an Access database. > >> I would like to extend its functionality by adding a > macro > >> to the Access DB that > >> would add the requests to a "Vacation Calander" > >> (alias: "VacationCalendar") > >> in a shared public folder in Outlook. > >> > >> A subroutine that should do this is listed below. It > works > >> great if the Calendar used > >> is an individual user's calendar. However, the following > >> line produces a "The server mailbox > >> cannot be opened because this address book entry is not > an > >> e-mail user" error message, when the > >> "Vacation Calander" (alias: "VacationCalendar") in a > >> shared public folder in used. > >> > >> > >> Set objFolder = _ > >> objNS.GetSharedDefaultFolder(objRecip, _ > >> 9) 'olFolderCalendar > >> > >> > >> The public folder has e-mail access enabled and appears > in > >> the Outlook global address list. > >> > >> Any insight would be appreciated. > >> > >> Thanks in advance. > >> > >> Keith > >> > >> > >> > >> > >> > >> > >> > >> ================== > >> Sub CreateOtherUserAppointment() > >> Dim objApp As Outlook.Application > >> Dim objNS 'As Outlook.NameSpace > >> Dim objFolder 'As Outlook.MAPIFolder > >> Dim objDummy 'As Outlook.MailItem > >> Dim objRecip 'As Outlook.Recipient > >> Dim objAppt 'As Outlook.AppointmentItem > >> Dim strMsg 'As String > >> Dim strName 'As String > >> On Error Resume Next > >> > >> ' ### name of Calendar to use ### > >> strName = "VacationCalendar" > >> > >> Set objApp = New Outlook.Application > >> Set objNS = objApp.GetNamespace("MAPI") > >> Set objDummy = objApp.CreateItem(0) 'olMailItem > >> > >> Set objRecip = objDummy.Recipients.Add(strName) > >> objRecip.Resolve > >> If Not objRecip.Resolve Then myItem.Display > >> If objRecip.Resolved Then > >> > >> On Error Resume Next > >> Set objFolder = _ > >> objNS.GetSharedDefaultFolder(objRecip, _ > >> 9) 'olFolderCalendar > >> If Not objFolder Is Nothing Then > >> Set objAppt = objFolder.Items.Add > >> If Not objAppt Is Nothing Then > >> With objAppt > >> .Subject = "Test Appointment" > >> .Start = #4/21/2004 8:00:00 AM# > >> .End = #4/21/2004 4:00:00 PM# > >> .Location = Town & Gown > >> .BusyStatus = 1 > >> .Body = "Stop the insanity.... " > >> .AllDayEvent = False > >> .Save > >> End With > >> End If > >> End If > >> Else > >> MsgBox "Could not find " & Chr(34) & strName & > Chr > >> (34), , _ > >> "User not found" > >> End If > >> > >> Set objApp = Nothing > >> Set objNS = Nothing > >> Set objFolder = Nothing > >> Set objDummy = Nothing > >> Set objRecip = Nothing > >> Set objAppt = Nothing > >> End Sub > >> ================== > >> > > > > > >. > > |
|
|
|
#5 |
|
Guest
Posts: n/a
|
To me that's obvious. It can be either:
...Subject or ...Start and .End What I was looking for assistance with actual the code to to look up the appointment. Keith E. >-----Original Message----- >The real question is, "How would I find the appointment that the user wants >to cancel?" To answer that you'll have to go back to the business logic of >your application and decide how you want the user to indicate that they want >to cancel a vacation. Once you've figured that out, you should know what >information you'll have available to look up the appointment. Once you have >an AppointmentItem object, you can use the Delete method to remove it. >-- >Sue Mosher, Outlook MVP >Author of > Microsoft Outlook Programming - Jumpstart for > Administrators, Power Users, and Developers > http://www.outlookcode.com/jumpstart.aspx > > >"Keith E." <kengelhardt@designforum.com> wrote in message >news:468201c42bcf$d646b800$a601280a@phx.gbl... >> Thanks for the tip. By Setting a reference to an Exchange >> Public Folder >> (http://www.fabalou.com/Outlook/GetOutlookFolder.asp), I >> was able to post a appointment to the calendar. >> >> Any idea how I would remove the appointment from the >> calendar via code, if a user cancels the vacation? >> >> Keith E. >> >> >-----Original Message----- >> >The message means exactly what it says: You can't use >> that method to get to >> >a public folder. It works only on default mailbox folders. >> > >> >To get a folder in Public Folders, you need to walk the >> folder hierarchy >> >using the Folders collections or use a function that does >> that for you. See >> >http://www.outlookcode.com/d/code/getfolder.htm > >> > >> > >> >"Keith E." <kengelhardt@designforum.com> wrote in message >> >news:44f601c42b99$1fe5efd0$a001280a@phx.gbl... >> >> I have a web application that stores vacation requests >> in >> >> an Access database. >> >> I would like to extend its functionality by adding a >> macro >> >> to the Access DB that >> >> would add the requests to a "Vacation Calander" >> >> (alias: "VacationCalendar") >> >> in a shared public folder in Outlook. >> >> >> >> A subroutine that should do this is listed below. It >> works >> >> great if the Calendar used >> >> is an individual user's calendar. However, the following >> >> line produces a "The server mailbox >> >> cannot be opened because this address book entry is not >> an >> >> e-mail user" error message, when the >> >> "Vacation Calander" (alias: "VacationCalendar") in a >> >> shared public folder in used. >> >> >> >> >> >> Set objFolder = _ >> >> objNS.GetSharedDefaultFolder(objRecip, _ >> >> 9) 'olFolderCalendar >> >> >> >> >> >> The public folder has e-mail access enabled and appears >> in >> >> the Outlook global address list. >> >> >> >> Any insight would be appreciated. >> >> >> >> Thanks in advance. >> >> >> >> Keith >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> >> ================== >> >> Sub CreateOtherUserAppointment() >> >> Dim objApp As Outlook.Application >> >> Dim objNS 'As Outlook.NameSpace >> >> Dim objFolder 'As Outlook.MAPIFolder >> >> Dim objDummy 'As Outlook.MailItem >> >> Dim objRecip 'As Outlook.Recipient >> >> Dim objAppt 'As Outlook.AppointmentItem >> >> Dim strMsg 'As String >> >> Dim strName 'As String >> >> On Error Resume Next >> >> >> >> ' ### name of Calendar to use ### >> >> strName = "VacationCalendar" >> >> >> >> Set objApp = New Outlook.Application >> >> Set objNS = objApp.GetNamespace("MAPI") >> >> Set objDummy = objApp.CreateItem(0) 'olMailItem >> >> >> >> Set objRecip = objDummy.Recipients.Add(strName) >> >> objRecip.Resolve >> >> If Not objRecip.Resolve Then myItem.Display >> >> If objRecip.Resolved Then >> >> >> >> On Error Resume Next >> >> Set objFolder = _ >> >> objNS.GetSharedDefaultFolder(objRecip, _ >> >> 9) 'olFolderCalendar >> >> If Not objFolder Is Nothing Then >> >> Set objAppt = objFolder.Items.Add >> >> If Not objAppt Is Nothing Then >> >> With objAppt >> >> .Subject = "Test Appointment" >> >> .Start = #4/21/2004 8:00:00 AM# >> >> .End = #4/21/2004 4:00:00 PM# >> >> .Location = Town & Gown >> >> .BusyStatus = 1 >> >> .Body = "Stop the insanity.... " >> >> .AllDayEvent = False >> >> .Save >> >> End With >> >> End If >> >> End If >> >> Else >> >> MsgBox "Could not find " & Chr(34) & strName & >> Chr >> >> (34), , _ >> >> "User not found" >> >> End If >> >> >> >> Set objApp = Nothing >> >> Set objNS = Nothing >> >> Set objFolder = Nothing >> >> Set objDummy = Nothing >> >> Set objRecip = Nothing >> >> Set objAppt = Nothing >> >> End Sub >> >> ================== >> >> >> > >> > >> >. >> > > > >. > |
|
|
|
#6 |
|
Guest
Posts: n/a
|
Outlook provides the MAPIFolder.Items.Find and .Restrict methods for looking
up items in a folder based on certain criteria. Find would be better in a case like this where you expect to return a single item. Basics on how to use Find are covered in its Help topic. Searching on dates can be tricky -- see http://www.outlookcode.com/d/finddate.htm -- Sue Mosher, Outlook MVP Author of Microsoft Outlook Programming - Jumpstart for Administrators, Power Users, and Developers http://www.outlookcode.com/jumpstart.aspx "Keith E." <kengelhardt@designforum.com> wrote in message news:4f2801c42c71$00536b10$a301280a@phx.gbl... > To me that's obvious. It can be either: > > ..Subject or > ..Start and .End > > What I was looking for assistance with actual the code to > to look up the appointment. > > Keith E. > > >-----Original Message----- > >The real question is, "How would I find the appointment > that the user wants > >to cancel?" To answer that you'll have to go back to the > business logic of > >your application and decide how you want the user to > indicate that they want > >to cancel a vacation. Once you've figured that out, you > should know what > >information you'll have available to look up the > appointment. Once you have > >an AppointmentItem object, you can use the Delete method > to remove it. > > > > > >"Keith E." <kengelhardt@designforum.com> wrote in message > >news:468201c42bcf$d646b800$a601280a@phx.gbl... > >> Thanks for the tip. By Setting a reference to an > Exchange > >> Public Folder > >> (http://www.fabalou.com/Outlook/GetOutlookFolder.asp), I > >> was able to post a appointment to the calendar. > >> > >> Any idea how I would remove the appointment from the > >> calendar via code, if a user cancels the vacation? |
|
![]() |
|
| Thread Tools | |
| Rate This Thread | |
|
|

Main Page 

