I have been putting together code from bits I have found online that will create an appointment in Outlook from a date field in my form.
My form has a number of dates and I need to create appointments for each one. Is there any way I can incorporate that into the existing code? Or will I need to add command buttons for each date?
The date fields are:
[Date Template Made]
[Date of Top Cut]
[Date of Bowl Cut]
(I know I have made the school girl error of spaces but have learnt my lesson)
I am a self taught user but I get stuck on loops. Any help/advise is much appreciated
Here is my code so far:
My form has a number of dates and I need to create appointments for each one. Is there any way I can incorporate that into the existing code? Or will I need to add command buttons for each date?
The date fields are:
[Date Template Made]
[Date of Top Cut]
[Date of Bowl Cut]
(I know I have made the school girl error of spaces but have learnt my lesson)
I am a self taught user but I get stuck on loops. Any help/advise is much appreciated
Here is my code so far:
Code:
Private Sub CreateAppt_Click()
If Me.Dirty Then
Me.Dirty = False
End If
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
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 olappt = olapp.CreateItem(1) ' olAppointmentItem
Start = Me.Date_Template_Made
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.Date_Template_Made, "") & " " & ("07:00")
' Set the End Property Value
.End = Nz(Me.Date_Template_Made, "") & " " & ("17:00")
.Subject = Nz(Me.Job_Name, vbNullString)
.Body = Nz(Me.Notes, vbNullString)
.Categories = "TemplateMade"
.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
If Me.Dirty Then
Me.Dirty = False
End If
' Inform the user
MsgBox "Appointment Added!", vbInformation
End Sub