Outlook shouldn't crash when you attempt to open it from Access. Try the
code below and see if you still experience a crash. Also check to see how
many times Outlook is running in the background, not closed (use taskmanager
for this if your OS supports it).
Code:
Dim ol As Outlook.Application
Const CANT_CREATE_OBJECT As Integer = 429
'turn off error handling
'test first to see if outlook is open
On Error Resume Next
Set ol = GetObject(Class:="Outlook.Application")
If Err.Number = CANT_CREATE_OBJECT Then
Set ol = CreateObject(Class:="Outlook.Application")
End If
'turn on error handling, if you have any
On Error Goto ERR_TRAP
'rest of your code past here
This method relies on the error raised when you try the "GetObject"
function. If you go to the website at
http://www.mvps.org/access/ you can
find a function under the "APIs/Find Out if an Application is Currently
Running" link that will allow you to test for various office applications
including Outlook, providing a different method of achieving the same
result. Also there is "Close Another Application" which you will find useful
for this type of problem. I have rolled my own versions of these in the
past, but the ones on this site are just as good or better. There are many
good examples on the site and I highly recommend adding it to your
"Favorites".
Jeffrey R. Bailey
"deko" <dj****@hotmail.com> wrote in message
news:O2******************@newssvr25.news.prodigy.c om...
When adding Outlook Appointment Items from Access, should I use:
Set ol = New Outlook.Application
--or--
Set ol = CreateObject("Outlook.Application")
Outlook seems to crash either way.
The Outlook application (and/or Calendar) may or may not be open when this
sub runs.
Here is code:
Private Sub AddAppt_Click()
Dim ol As Outlook.Application
Dim ola As Outlook.AppointmentItem
Set ol = New Outlook.Application
'--or--
'Set ol = CreateObject("Outlook.Application")
Set ola = ol.CreateItem(olAppointmentItem)
With ola
.Start = Me!SomeDate
.Subject = Me!Subject
.Location = Me!Location
.AllDayEvent = True
.ReminderMinutesBeforeStart = "1440"
.Body = Me!Body
.ReminderSet = True
.Save
.Close (olSave)
End With
End Sub