Link to home
Start Free TrialLog in
Avatar of andrewpiconnect
andrewpiconnectFlag for United Kingdom of Great Britain and Northern Ireland

asked on

synchronising information between an msaccess table and outlook calendar (part 2)

Following some excellant code for the above (see Q_21410818.html), I now wish this to check that if the field has already updated the outlook calendar entry it does not continue to duplicate thereafter.

Also, is it possible for this code to run automatically every time outlook is opened and then say, every 1hr or so when open?
Avatar of David Lee
David Lee
Flag of United States of America image

I haven't forgotten about this question, just haven't gotten to it yet.
Avatar of andrewpiconnect

ASKER

ok - many thanks, look forward to hearing from you

ASKER CERTIFIED SOLUTION
Avatar of David Lee
David Lee
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Many thanks - will be working on this tonight
Unless I got caught in a time warp this isn't the night after as I had promissed in my last post.  This slipped my mind.  I forgot about it, plain and simple.  I'm very sorry about that.  Hopefully this will still be useful though.

This will run the SyncCalendar macro when Outlook starts, and once each hour there after.  To use it:
1.  Copy the code and place it in the ThisOutlookSession module.
2.  Create a Task with a Subject of Run SyncCalendar.  
3.  Check the Reminder box and save the task.
4.  Exit Outlook
5.  Start Outlook.  SyncCalendar should run and then set a reminder on the Run SyncCalendar task one hour into the future.  When the reminder for the task fires an hour later, SyncCalendar shoudl run and again set the reminder forward by one hour.  If you don't like a subject of Run SyncCalendar, then you can use something else so long as you change all references to Run SyncCalendar to the new name.


Public WithEvents objReminders As Outlook.Reminders

Private Sub Application_Startup()
    Dim objTasks As MAPIFolder, _
        objTask As TaskItem
    Set objTasks = Application.GetNamespace("MAPI").GetDefaultFolder(olFolderTasks)
    SyncCalendar
    'Find the task named Run SyncCalendar
    Set objTask = objTasks.Items.Find("[Subject] = 'Run SyncCalendar'")
    'Found it
    If objTask.Class = olTask Then
        'Set the reminder time one hour into the future
        objTask.ReminderTime = DateAdd("h", 1, Now)
        objTask.Save
        Set objReminders = Application.Reminders
    End If
    Set objTask = Nothing
    Set objTasks = Nothing
End Sub

Private Sub objReminders_ReminderFire(ByVal ReminderObject As Reminder)
    Dim objTaskItem As Outlook.TaskItem
    'Is the reminder for a task
    If ReminderObject.Item.Class = olTask Then
        Set objTaskItem = ReminderObject.Item
        'Is the reminder for our task
        If objTaskItem.Subject = "Run SyncCalendar" Then
            SyncCalendar
            objTaskItem.ReminderTime = DateAdd("h", 1, Now)
            objTaskItem.Save
        End If
    End If
    Set objTaskItem = Nothing
End Sub
Many thanks  -  - will begin work this weekend and hope I can get it going on my system