Help! putting dates from access into PUBLIC calendar,



at the moment i am exporting some dates into an appointment from access using
a command button which does this ---
Private Sub cmdAddAppt_Click()
On Error GoTo Add_Err
'Save record first to be sure required fields are filled.
DoCmd.RunCommand acCmdSaveRecord
'Exit the procedure if appointment has been added to Outlook.
Dim objOutlook As Outlook.Application

Dim objAppt As Outlook.AppointmentItem
Dim objRecurPattern As Outlook.RecurrencePattern
Set objOutlook = CreateObject("Outlook.Application")
Set objAppt = objOutlook.CreateItem(olAppointmentItem)
With objAppt
.Start = Me!Starthire
.Duration = Me!Days
.Subject = Me!JobNo
.end = Me!Endhire
If Not IsNull(Me!Text223) Then .Body = Me!Text223
If Not IsNull(Me!City) Then .Location = Me!City

.Close (olSave)
End With
'Release the AppointmentItem object variable.
Set objAppt = Nothing
'Release the object variables.
Set objOutlook = Nothing
Set objRecurPattern = Nothing
'Set the AddedToOutlook flag, save the record, display
'a message.
DoCmd.RunCommand acCmdSaveRecord
MsgBox "Appointment Added!"
Exit Sub
MsgBox "Error " & Err.Number & vbCrLf & Err.Description
Exit Sub
End Sub

However this puts it into the personal calendar and i need it to go into the
a public calendar...

I found this code that should work but i cant get them to work together...

Dim myFolder As Object

Set myNameSpace = myOlApp.GetNamespace("MAPI")

Set myFolder = myNameSpace.Folders("Public Folders")
Set myFolder = myFolder.Folders("All Public Folders")
Set myFolder = myFolder.Folders("name of folder")
'If the folder is just below the All Public Folders location. If it is
'elsewhere you keep adding Folders references until you hit the folder
'you want.

Set myFolderItems = myFolder.Items
Set objAppt = myFolderItems.Add(olAppointmentItem)

' olAppointmentItem is standard outlook form. If using custom form it must
be published in Organizational Forms

Can someone help me put it together so they work??





Sue Mosher [MVP-Outlook]

Items.Add is the right method. You need no arguments if you're creating an appointment with the standard form. What specifically doesn't work for you with that approach?

You didn't say where your target folder is located in the Public Folders hierarchy. You can either walk the folder hierarchy using the Folders collections or use a function that does that for you. See and, especially for public folders,


I'#m not that proficient with VB code so ive been taking snippets and trying
to get them to work together, if i simply paste the scond load of code into
the first one then it doesnt work, i was wondering if someone would be able
to put them together so it works. if i put it all together it comes up with
an object error. If someone could put it together how it 'should' work then
im sure it will. Basically im guessing if i put them together it doesnt work
becauase its contradicting itself in the code? is that right? The folder im
after is in public folders > all public folders > cks diary

Am i making sense!?



Sue Mosher [MVP-Outlook]

You have everything you need already in the code you originally posted. Basically, you need to:

a) Return a MAPIFolder object by walking the folder hierarchy.

b) Once you have that object, use its Items.Add method to add a new item to the folder.

Just put the correct name of the folder in the third Set myFolder = statement that you shared earlier.

Tip for next time: Explain exactly what code you are referring to rather than using vague terms like "second load of code." Remember no one here can look over your shoulder.
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question