A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Outlook » Calendar
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Adding an entry to a Calendar in a shared public folder with VBA



 
 
Thread Tools Display Modes
  #1  
Old April 26th, 2004, 03:15 PM
Keith E.
external usenet poster
 
Posts: n/a
Default Adding an entry to a Calendar in a shared public folder with VBA

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  
Old April 26th, 2004, 04:46 PM
Sue Mosher [MVP-Outlook]
external usenet poster
 
Posts: n/a
Default Adding an entry to a Calendar in a shared public folder with VBA

Please see my response to your earlier post in the
microsoft.public.outlook.program_vba group, which is the better forum for
programming questions.

--
Sue Mosher, Outlook MVP
Author of
Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
http://www.outlookcode.com/jumpstart.aspx


"Keith E." wrote in message
...
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
==================



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 08:16 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.