PDA

View Full Version : Add Appointment From Custom Form



wingers
10-18-2013, 08:25 AM
Hi

I am creating a custom page on a contact form which contains various expiry dates for services I offer

I would like to code using VBA so that when I change a date in a user-defined field on a contact form i.e. "renewal date", it then automatically adds a calendar appointment for the chosen date with the contacts name appended

e.g. if I have a contact called John Smith and I change the value of the renewal date field on his contact to say 31/11/13, it then adds an all-day calendar appointment for the 31/11/13 which says "renewal date - john smith"

Thanks in advance for any help

Regards

using outlook 2013 / windows 8.1

SamT
10-19-2013, 07:11 AM
I changed the Thread Title to better describe your problem and possibly attract more answers.

mrojas
10-20-2013, 08:39 AM
On the either the Change or AfterUpdate event of the control, trigger the following code to execute, passing to it the required arguments.


Public Sub s_AddOutlookAppointment(strSubject As String, strEmail As String, strAddress As String, dteDate As Date)
' By: Milton Rojas Rojas@astound.net
' Date: 01/23/2005

Dim strDate As String
Dim objOutlook As New Outlook.Application
Dim objAppt As AppointmentItem

On Error GoTo OutError

Set objAppt = objOutlook.CreateItem(olAppointmentItem)
With objAppt
.Subject = strSubject ' Appointment's Subject line
.Start = dteDate ' Appointment's starting time"
.end = dteDate ' Appointment's ending time"
.Location = strEmail ' Appointment's location
.ReminderSet = True ' Set Reminder to 15 minutes
.ReminderMinutesBeforeStart = 45 ' before the start of the appointment
.Save ' Save the appointment
End With
ExitPoint:
Set objAppt = Nothing
Set objOutlook = Nothing
Exit Sub
OutError:
MsgBox "s_AddOutlookAppoinment: " & Err.Description, vbExclamation, "Error"
GoTo ExitPoint
End Sub