Johnsonsimon
Registered User.
- Local time
- Today, 06:37
- Joined
- May 5, 2012
- Messages
- 45
Hello all.
I have followed the other threads on here regarding using VBA to add appointments to outlook and it works great, everything works a treat, but ONLY if I have opened Outlook and have it running.
If I dont open it prior to the code running then the appointment is not created. The little Outlook icons flashes up in the task bar to show something is happening, but no appointment is created. If this were just a DB for me then I wouldnt worry, but I cant guarantee that the end users will ensure they have Outlook running.
Any assistance will be muchly appreciated.
Here is my code:
I have followed the other threads on here regarding using VBA to add appointments to outlook and it works great, everything works a treat, but ONLY if I have opened Outlook and have it running.
If I dont open it prior to the code running then the appointment is not created. The little Outlook icons flashes up in the task bar to show something is happening, but no appointment is created. If this were just a DB for me then I wouldnt worry, but I cant guarantee that the end users will ensure they have Outlook running.
Any assistance will be muchly appreciated.
Here is my code:
Code:
Private Sub AddAppt_Click()
On Error GoTo AddAppt_Err
' Save record first to be sure required fields are filled.
DoCmd.RunCommand acCmdSaveRecord
' Exit the procedure if appointment has been added to Outlook.
If Me!AddedToOutlook = True Then
MsgBox "This appointment already added to Microsoft Outlook. Changes made here will not be updated on Outlook."
Exit Sub
' Add a new appointment.
Else
Dim outobj As Outlook.Application
Dim outappt As Outlook.AppointmentItem
Set outobj = CreateObject("Outlook.Application")
Set outappt = outobj.CreateItem(olAppointmentItem)
With outappt
.Start = Me![Collection Date] & " " & Me![Collection Time]
.Duration = Me!Duration
.Subject = [Forms]![frm_Job]![Job Number] & "-" & [Forms]![frm_Job]![Client Name] & " - " & [Forms]![frm_Job]![Passenger Name] & " (" & [Forms]![frm_Job]![Driver] & ")"
.Mileage = [Forms]![frm_Job]![Job Number]
If Not IsNull(Me![Additional Notes]) Then .Body = "From: " & [Forms]![frm_Job]![Location Name] & Chr$(13) & "To: " & [Forms]![frm_Job]![Location Name_tbl_LocationDropoff] & Chr$(13) & Me![Additional Notes]
If Not IsNull([Forms]![frm_Job]![Location Name]) Then .Location = [Forms]![frm_Job]![Location Name]
.ReminderSet = False
.Save
End With
End If
' Release the Outlook object variable.
Set outobj = Nothing
' Set the AddedToOutlook flag, save the record, display a message.
Me!AddedToOutlook = True
DoCmd.RunCommand acCmdSaveRecord
MsgBox "Appointment Added to Outlook!"
Exit Sub
AddAppt_Err:
MsgBox "Error " & Err.Number & vbCrLf & Err.Description
Exit Sub
End Sub