Add to Outlook..where am I going wrong? (1 Viewer)

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:

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
 

NigelShaw

Registered User.
Local time
Today, 06:37
Joined
Jan 11, 2008
Messages
1,573
I'm not on my pc so I can't post code but, look up my name and I posted code for this a while ago. It can post to outlook without it being open.

Thanks
Nigel

Sent from my OMNIA7 using Board Express
 

Johnsonsimon

Registered User.
Local time
Today, 06:37
Joined
May 5, 2012
Messages
45
thanks nigel,

can you remember the name of the thread?

cheers
 

NigelShaw

Registered User.
Local time
Today, 06:37
Joined
Jan 11, 2008
Messages
1,573
No idea mate. I'll have a look tomorrow :)



Sent from my OMNIA7 using Board Express
 

NigelShaw

Registered User.
Local time
Today, 06:37
Joined
Jan 11, 2008
Messages
1,573
Hi,

im at my PC and found a sample db i made ages ago. You can modify how ever you like. There is a public module that has the settings in etc and i added this to let you demo what you could do-
Code:
Sub AddAppointment()
Call AddAppClosedOutlk("20/08/2012", "Demo App Subject")
End Sub
Sub DeleteAppointment()
Call DeleteAppointmentItemBySubject("Demo App Subject")

End Sub

Let me know how you get on :)


cheers
 

Attachments

  • OutlookApps.accdb
    564 KB · Views: 98

Users who are viewing this thread

Top Bottom