Codetwo Public Folders structure for vba

Status
Not open for further replies.

Melinda

New Member
Outlook version
Outlook 2010 32 bit
Email Account
Hi, I have recently installed Codetwo Public Folders on my client's computers so they can shared one calendar including the category colours. It works great.
I have created an Access database to enter appointments into the calendar using the following line of code:
Code:
Set olfolder = olapp.GetNamespace("mapi").PickFolder
But I would like the appointments to post to the calendar without the user having to choose the calendar each time.
This code works fine on the host of the shared calendar but not on the other computers.
Code:
Set olfolder = objOutlook.GetNamespace("MAPI").GetDefaultFolder(olFolderCalendar).Folders("Deliveries")
My issue is that I can't figure out how to make this happen. I have searched all over the internet but I haven't been able to find something that works, or that I can understand and adapt. (I am a self taught code writer...so not very good)
Support at Codetwo weren't able to shed any light either.
The Pickfolder window shows the following structure:
C2PublicFolders - Other User's Folders - HUNTLYJOINERY\Tony - Calendar - Deliveries

this is the full code that I am using in my database:
Code:
Private Sub cmdAddCalendars_Click()
     Me.Dirty = False
If Me.chkAddedtoOutlook = True Then
    MsgBox "This appointment has already been added to Microsoft Outlook", vbCritical
    ' Exit the procedure
    Exit Sub
Else
    ' Add a new appointment.
' Use late binding to avoid the "Reference" issue
Dim olapp As Object ' Outlook.Application
Dim olappt As Object ' olAppointmentItem
Dim i As Integer
Dim ctl As Control
Dim cat As Control
Dim olfolder As Object

If isAppThere("Outlook.Application") = False Then
    ' Outlook is not open, create a new instance
    Set olapp = CreateObject("Outlook.Application")
Else
    ' Outlook is already open--use this method
    Set olapp = GetObject(, "Outlook.Application")
End If
Set olfolder = olapp.GetNamespace("mapi").PickFolder
  
    Set olappt = olfolder.Items.Add ' olAppointmentItem
 
   
    With olappt
    ' If There is no Start Date or Time on
    ' the Form use Nz to avoid an error
    
    ' Set the Start Property Value
    .Start = Nz(Me.DelDate, "") & " " & Nz(Me.txtTime, "")
    .Subject = Nz(Me.Delivery & " " & Me.OrderNumber & " " & Me.Customer & " " & Me.NumberofDoors, vbNullString)
    .Mileage = Nz(Me.OrderNumber, vbNullString)
    .Categories = Nz(Me.Stage, vbNullString)
    .ReminderSet = False
   
         .Save
    End With
   
    End If ' Release the Outlook object variables.
    Set olappt = Nothing
    Set olapp = Nothing    ' Set chkAddedToOutlook to checked
    Me.chkAddedtoOutlook = True
    ' Save the Current Record because we checked chkAddedToOutlook
      Me.Dirty = False
  
    ' Inform the user
    MsgBox "Appointment Added!", vbInformation
End Sub
Function isAppThere(appname) As Boolean
On Error Resume Next
   
    Dim objApp As Object
    isAppThere = True
   
    Set objApp = GetObject(, appname)
    If Err.Number <> 0 Then isAppThere = False
   
End Function
Any guidance is very much appreciated
 
I don't know what kind of folders PublicFolders creates. Is
"C2PublicFolders - Other User's Folders - HUNTLYJOINERY"
really one folder name? Probably not. If the first folder is "C2PublicFolders", see if it's a store, which you'd access via:
set olfolder=application.session.folders("C2PublicFolders")
From there you could access its next child folder by name.
 
Thanks, I'll give it a shot. I have also attached a picture of the outlook structure as I see it using Pickfolder
 

Attachments

  • Capture.JPG
    Capture.JPG
    52.8 KB · Views: 665
Ok, so "C2PublicFolders" is indeed a store, which you can access as shown above.

Did you name this one "HUNTLYJOINERY\Tony"?

You shouldn't use the backslash within a folder name as it actually separates two folders. So, with the bs within the name, it is more difficult to identify by code what the next folder name is.
 
This one could be easier for you: Use the pickfolder to get the ref on the folder, then print its IDs:
debug.print olfolder,.entryid, olfolder.storeid

Copy the IDs from the debug window (strg+g), and replace the pickfolder in the code by this one:
set olfolder=application.session.getfolderfromid(entryid, storeid)

You'd need to do this on each computer as the IDs will be different on each one.
 
Thanks for your help. This may be a stupid question, but where do I run debug.print olfolder,.entryid, olfolder.storeid
I added to my code after Pickfolder but got Compile error: Invalid or unqualified reference
 
Thanks for the code. I am way out of my depth on this one.
I ran the debug.print and got the following:
00000000F6B257AFDA21B049BB29B33302C83EEC22810000

0000000038A1BB1005E5101AA1BB08002B2A56C200006D737073742E646C6C00000000004E495441F9BFB80100AA0037D96E0000000043003A005C00550073006500720073005C006D0065006C005C0044006F00630075006D0065006E00740073005C004F00750074006C006F006F006B002000460069006C00650073005C004F00750074006C006F006F006B002E007000730074000000

I tried to add this into my code and not only am I getting a Compile Error on .Session but I can't seem to get work the ID's into my code.
Sorry to be a pain, but could you maybe show my using my code how I should be doing it?
 
This is my original code
Code:
Private Sub cmdAddCalendars_Click()
     Me.Dirty = False
If Me.chkAddedtoOutlook = True Then
    MsgBox "This appointment has already been added to Microsoft Outlook", vbCritical
    ' Exit the procedure
    Exit Sub
Else
    ' Add a new appointment.
' Use late binding to avoid the "Reference" issue
Dim olapp As Object ' Outlook.Application
Dim olappt As Object ' olAppointmentItem
Dim i As Integer
Dim ctl As Control
Dim cat As Control
Dim olfolder As Object

If isAppThere("Outlook.Application") = False Then
    ' Outlook is not open, create a new instance
    Set olapp = CreateObject("Outlook.Application")
Else
    ' Outlook is already open--use this method
    Set olapp = GetObject(, "Outlook.Application")
End If
Set olfolder = olapp.GetNamespace("mapi").PickFolder
 
    Set olappt = olfolder.Items.Add ' olAppointmentItem
  
    With olappt
    ' If There is no Start Date or Time on
    ' the Form use Nz to avoid an error
   
    ' Set the Start Property Value
    .Start = Nz(Me.DelDate, "") & " " & Nz(Me.txtTime, "")
    .Subject = Nz(Me.Delivery & " " & Me.OrderNumber & " " & Me.Customer & " " & Me.NumberofDoors, vbNullString)
    .Mileage = Nz(Me.OrderNumber, vbNullString)
    .Categories = Nz(Me.Stage, vbNullString)
    .ReminderSet = False
  
         .Save
    End With
  
    End If ' Release the Outlook object variables.
    Set olappt = Nothing
    Set olapp = Nothing    ' Set chkAddedToOutlook to checked
    Me.chkAddedtoOutlook = True
    ' Save the Current Record because we checked chkAddedToOutlook
      Me.Dirty = False
 
    ' Inform the user
    MsgBox "Appointment Added!", vbInformation
End Sub
Function isAppThere(appname) As Boolean
On Error Resume Next
  
    Dim objApp As Object
    isAppThere = True
  
    Set objApp = GetObject(, appname)
    If Err.Number <> 0 Then isAppThere = False
  
End Function

I have added your line below and
Dim StoreId As String
Dim EntryId As String
But when I tried to Set the Ids I got more errors. I haven't been able to find anything similar online to help me so I took them out again.

Code:
Private Sub cmdAddCalendar_Click()
     Me.Dirty = False
If Me.chkAddedtoOutlook = True Then
    MsgBox "This appointment has already been added to Microsoft Outlook", vbCritical
    ' Exit the procedure
    Exit Sub
Else
    ' Add a new appointment.
' Use late binding to avoid the "Reference" issue
Dim olapp As Object ' Outlook.Application
Dim olappt As Object ' olAppointmentItem
Dim i As Integer
Dim ctl As Control
Dim cat As Control
Dim olfolder As Object
Dim StoreId As String
Dim EntryId As String

If isAppThere("Outlook.Application") = False Then
    ' Outlook is not open, create a new instance
    Set olapp = CreateObject("Outlook.Application")
Else
    ' Outlook is already open--use this method
    Set olapp = GetObject(, "Outlook.Application")
End If
Set olfolder = Application.Session.GetFolderFromID(EntryId, StoreId)

    Set olappt = olfolder.Items.Add ' olAppointmentItem
 
   
    With olappt
    ' If There is no Start Date or Time on
    ' the Form use Nz to avoid an error
    
    ' Set the Start Property Value
    .Start = Nz(Me.StartDate, "") & " " & Nz(Me.StartTime, "")
    .End = Nz(Me.EndDate, "") & " " & Nz(Me.EndTime, "")
    .Subject = Nz(Me.Employee & " Leave", vbNullString)
    .Mileage = Nz(Me.ID, vbNullString)
    .ReminderSet = False
   
         .Save
    End With
   
    End If ' Release the Outlook object variables.
    Set olappt = Nothing
    Set olapp = Nothing    ' Set chkAddedToOutlook to checked
    Me.chkAddedtoOutlook = True
    ' Save the Current Record because we checked chkAddedToOutlook
      Me.Dirty = False
     'Return focus to Access
 
    ' Inform the user
    MsgBox "Appointment Added!", vbInformation

End Sub
Function isAppThere(appname) As Boolean
On Error Resume Next
   
    Dim objApp As Object
    isAppThere = True
   
    Set objApp = GetObject(, appname)
    If Err.Number <> 0 Then isAppThere = False
   
End Function
 
You didn't paste both printed ID values.
EntryID="paste the printed value from the debug window here"
After that you can use the variable for the GetFolderFromID function.
 
I have added both the ID's in but I am still get the following error for .Session

Compile Error: Method or Data Member not found

I tried setting the Session property but got the same error. Am I missing something?

Code:
Private Sub cmdAddCalendar_Click()
     Me.Dirty = False
If Me.chkAddedtoOutlook = True Then
    MsgBox "This appointment has already been added to Microsoft Outlook", vbCritical
    ' Exit the procedure
    Exit Sub
Else
    ' Add a new appointment.
' Use late binding to avoid the "Reference" issue
Dim olapp As Object ' Outlook.Application
Dim olappt As Object ' olAppointmentItem
Dim i As Integer
Dim ctl As Control
Dim cat As Control
Dim olfolder As Object
Dim StoreId As String
Dim EntryId As String

If isAppThere("Outlook.Application") = False Then
    ' Outlook is not open, create a new instance
    Set olapp = CreateObject("Outlook.Application")
Else
    ' Outlook is already open--use this method
    Set olapp = GetObject(, "Outlook.Application")
End If
EntryId = "00000000F6B257AFDA21B049BB29B33302C83EEC22810000"
StoreId = "0000000038A1BB1005E5101AA1BB08002B2A56C200006D737073742E646C6C00000000004E495441F9BFB80100AA0037D96E0000000043003A005C00550073006500720073005C006D0065006C005C0044006F00630075006D0065006E00740073005C004F00750074006C006F006F006B002000460069006C00650073005C004F00750074006C006F006F006B002E007000730074000000"
Set olfolder = Application.Session.GetFolderFromID(EntryId, StoreId)
    Set olappt = olfolder.Items.Add ' olAppointmentItem
 
   
    With olappt
    ' If There is no Start Date or Time on
    ' the Form use Nz to avoid an error
    
    ' Set the Start Property Value
    .Start = Nz(Me.StartDate, "") & " " & Nz(Me.StartTime, "")
    .End = Nz(Me.EndDate, "") & " " & Nz(Me.EndTime, "")
    .Subject = Nz(Me.Employee & " Leave", vbNullString)
    .Mileage = Nz(Me.ID, vbNullString)
    .ReminderSet = False
   
         .Save
    End With
   
    End If ' Release the Outlook object variables.
    Set olappt = Nothing
    Set olapp = Nothing    ' Set chkAddedToOutlook to checked
    Me.chkAddedtoOutlook = True
    ' Save the Current Record because we checked chkAddedToOutlook
      Me.Dirty = False
     'Return focus to Access
 
    ' Inform the user
    MsgBox "Appointment Added!", vbInformation

End Sub
Function isAppThere(appname) As Boolean
On Error Resume Next
   
    Dim objApp As Object
    isAppThere = True
   
    Set objApp = GetObject(, appname)
    If Err.Number <> 0 Then isAppThere = False
   
End Function
 
Code:
Set olfolder = Application.Session.GetFolderFromID(EntryId, StoreId)
Is this line raising the error? If so, it doesn't run in Outlook, does it? If I'm right, use olapp.Session... as Application doesn't point to Outlook, but to the application the code runs in.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
C reminders not synced by CodeTwo Sync for iCloud Using Outlook 2
W FYI: CodeTwo Sync for iCloud is FREE now! Using Outlook 0
V Anyone Using CodeTwo Sync for iCloud ? Using Outlook 28
S How to get the actual Public Folder path from Favourites Folders Outlook VBA and Custom Forms 3
B Sync Outlook Public Folders to Contacts Using Outlook 2
J How to import many msg into different public folders in Outlook Outlook VBA and Custom Forms 7
A Moving Public Folders to New Database Exchange Server Administration 3
Fozzie Bear Shared Public Folders Access and Use Exchange Server Administration 0
A Created a personal group that now appears to be a public group Using Outlook 3
A Prevent connection to Public Folders on Exchange? Exchange Server Administration 3
R Call a Public Sub when a Flag is clicked on in the Message Preview pane Outlook VBA and Custom Forms 1
R Copy Outlook Public Folders to a File Server Shared Folder Using Outlook 0
J Calling a Public sub-routine from the script editor via VB script Outlook VBA and Custom Forms 4
F How to assign a task to a public task folder? Using Outlook 1
D How to handle filing of emails from an Inbox Subfolder to a specific Public folder Using Outlook 1
D Record Appointment to Calendar on "Public Folder" Outlook VBA and Custom Forms 13
R Problem with searching public folders Exchange 2013/16 Exchange Server Administration 2
C Outlook 2016: Searching in all (+public) folders Outlook VBA and Custom Forms 9
X Delay sending an email until the next working day (public holidays) Outlook VBA and Custom Forms 0
L Public folders permissions Exchange Server Administration 1
Diane Poremsky Mail-enable Exchange Public Folders Using Outlook 0
K Macro to search emails between two time slots on public folders with excel export Outlook VBA and Custom Forms 12
Diane Poremsky How to Send Email When Traveling or Using Public Wi-Fi Using Outlook 0
Diane Poremsky Data loss may occur during public folder migration Using Outlook 0
S Empty an Office365 public folder containing 20.000 messages Using Outlook 2
D Priasoft Public Folder Syncro? Exchange Server Administration 0
I Random Chinese characters in email copied from a pst file. Exchange Server 2016 Public Folder Exchange Server Administration 1
T Create new item in public folder using VBscript Outlook VBA and Custom Forms 1
P Public Folder email error, ndr returned. Exchange Server Administration 1
J Favorites in Public Folders issue Outlook VBA and Custom Forms 0
P Last Change attribute set after viewing a public folder contact Exchange Server Administration 0
L any ways to create shortcuts to a public mail folder Using Outlook 4
L Should public contacts folder appear in "People" nav pane? Using Outlook 1
N Public Folder Calendar Permissions Exchange Server Administration 4
V Macro to open Public Folders subfolder? Outlook VBA and Custom Forms 1
S Contacts disappear in public folder search Using Outlook 1
R How to Block from sending mail to public domain. Using Outlook 8
I how to create appointment using saved template onto public folder shared calendar Using Outlook 3
M How to copy attachments from a Public Folder in VBA Outlook VBA and Custom Forms 3
G Outlook 2013 - Default View for Public Folder Contacts Using Outlook 1
V Extracting user-defined details from a public folder Outlook VBA and Custom Forms 2
C Sync color categories on a Public Calendar across Office 365, PCs, Macs Using Outlook 1
C Ex2010 problems with mail-enabled public folders Exchange Server Administration 0
D How do I mail-enable a Public Folder Sub-folder in exchnage 2007 using shell ? Exchange Server Administration 0
A Outlook VBA - moving mail item to public folder using variable within path Using Outlook 6
E Outlook 2007 Saves .MSG E-Mails with attachment from Public Folders as RTF Using Outlook 0
P correct public folder migration exchange 2003 to 2010 Exchange Server Administration 1
S Pushing GAL to a public folder Exchange Server Administration 2
T Public Folder has many messages but can't be seen in Outlook Using Outlook 3
C How do I share/post my calendar to public folders Exchange Server Administration 3

Similar threads

Back
Top