Solved

How to adjust appointment start/end times in Outlook

Posted on 2009-04-06
5
376 Views
Last Modified: 2012-05-06
1st Question from Newbie...

Hi,

I have a number of various appointments that I create very often in my calendar and so have a macro and a series of buttons to help me do this.

The "CreateAppt" macro code is below and the code for each of the buttons goes like this:

Sub TrainLondon()

Call CreateAppt("Train: Bath Spa to London", 2, "Travel, Time & Expenses", True, 30, "")

End Sub

My problem is that I want to pick up when a train journey is selected and substitute the user selected start/end times (typically 06:30 and 08:30) for the actual train times of 06:43 and 08:29 ... I cannot seem to find right construct to set the objAppt.Start and objAppt.End values correctly. Obviously I need to capture the date the user selected and then use that to augment the start/end times.

Any help always appreciated.

Thanks!

Private Sub CreateAppt(strSubject, intBusyStatus, strCategories, bolRemindMe, intRemindMe, strBodyText)
    
    Dim objExpl As Outlook.Explorer
    Dim objFolder As Outlook.MAPIFolder
    Dim objCB As Office.CommandBarButton
    Dim objAppt As Outlook.AppointmentItem
    Dim objApptCustom As Outlook.AppointmentItem
    On Error Resume Next
    
    Set objExpl = Application.ActiveExplorer
    If Not objExpl Is Nothing Then
        Set objFolder = objExpl.CurrentFolder
        If objFolder.DefaultItemType = olAppointmentItem Then
            Set objCB = objExpl.CommandBars.FindControl(, 1106)
            If Not objCB Is Nothing Then
                objCB.Execute
                Set objAppt = Application.ActiveInspector.CurrentItem
                Set objApptCustom = objFolder.Items.Add("IPM.Appointment")
                With objApptCustom
                    .Subject = strSubject
                    .Start = objAppt.Start
                    .End = objAppt.End
                    If intBusyStatus = 0 Then .BusyStatus = olFree
                    If intBusyStatus = 1 Then .BusyStatus = olTentative
                    If intBusyStatus = 2 Then .BusyStatus = olBusy
                    If intBusyStatus = 3 Then .BusyStatus = olOutOfOffice
                    .Categories = strCategories
                    .ReminderSet = bolRemindMe
                    If bolRemindMe = True Then
                        .ReminderMinutesBeforeStart = intRemindMe
                    End If
                    .Body = strBodyText
                    .Save
                End With
                objAppt.Delete
            End If
        Else
            MsgBox ("You must be in your Calendar and select the Start/End times of the appointment.")
        End If
    End If
    
    Set objCB = Nothing
    Set objAppt = Nothing
    Set objApptCustom = Nothing
    Set objFolder = Nothing
    Set objExpl = Nothing
 
End Sub

Open in new window

0
Comment
Question by:Charltp5
  • 3
  • 2
5 Comments
 
LVL 76

Expert Comment

by:David Lee
ID: 24076143
Hi, Charltp5.

Sorry, but I'm not clear on the issue.  Are you saying that you need to prepend the date to the user selected start time?  
0
 
LVL 1

Author Comment

by:Charltp5
ID: 24076385
Say I select an appointment slot on 08/04/09 of 08:00 to 08:30 and I click on the button for the TrainLondon sub routine, in the CreateAppt routine I want to recognise it and instead of creating the appointment for 08:00 to 08:30 I want to create it for 06:43 to 08:29 on 08/04/09. When I select the same slot on 12/04/09 I want to create the appointment for 06:43 to 08:29 on 12/04/09.

So the date will vary depending on the objAppt value but the Start and End times will be change to the actual train times and not those the user has selected.

At present I select the appointment slot of dd/mm/yyyy and 06:30 to 08:30 and that is how the appointment is created. I want to change those times.

Something like...

If strSubject = "blah blah" Then
  objAppt.Start = "dd/mm/yyyy 06:43"
  objAppt.End = "dd/mm/yyyy 08:29"
End If
0
 
LVL 76

Accepted Solution

by:
David Lee earned 125 total points
ID: 24076901
If the date is already filled in and you just want to change the time then use something like this

    objAppt.Start = Format(objAppt.Start,"dd/mm/yy") & " 06:43"

Instead of setting End I recommend setting the Duration value instead.  It'll calculate End for you.
0
 
LVL 1

Author Closing Comment

by:Charltp5
ID: 31566946
Excellent! Thanks very much - worked a treat.
0
 
LVL 76

Expert Comment

by:David Lee
ID: 24077711
You're welcome.  Glad I could help.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will discuss some EI Capitan Mail app issues and provide some manual process to resolve them.
Read this checklist to learn more about the 15 things you should never include in an email signature.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

860 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question