472,989 Members | 3,054 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,989 software developers and data experts.

Basic Outlook Automation Question

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
Nov 12 '05 #1
3 4933
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

Nov 12 '05 #2
> Dim ol As Outlook.Application
Const CANT_CREATE_OBJECT As Integer =
On Error Resume Next
Set ol = GetObject(Class:="Outlook.Application")
If Err.Number = CANT_CREATE_OBJECT Then
Set ol = CreateObject(Class:="Outlook.Application")

I'll give it a whirl... but, I'm wondering if these are equivalent:

Set ol = CreateObject("Outlook.Application")
--and--
Set ol = CreateObject(Class:="Outlook.Application")

my guess is that they are
Nov 12 '05 #3
This is a couple of days late, but hopefully you will see it.

Yes, the two statements are equivalent in terms of execution and your code
did not contain a syntax error. I don't think I suggested that it did, but
if I did I apologize. The difference between the two statements is a
difference of style. I try as much as possible to follow a style of coding
the insures the maximum clarity for anyone reading my code (including myself
six months in the future when I may not be terribly familiar with the
problem that I had solved previously). As a result, I use the assignment
operator ":=" and named arguments.

Having said that, the fragment I posted was not complete. Within the "if
"statement the line:
Err.Clear
should be added to clear the handled error from the error object.

The code I posted was only an attempt to keep you from opening multiple
copies of Outlook, which I have never found to be good. I thought having
multiple copies open the background might be the problem with the crashing.

If you have discovered what was causing the crash you should post back to
the group so that your experience can help others in the future.
--
Jeffrey R. Bailey
"deko" <dj****@hotmail.com> wrote in message
news:S_*****************@newssvr27.news.prodigy.co m...
Dim ol As Outlook.Application
Const CANT_CREATE_OBJECT As Integer =
On Error Resume Next
Set ol = GetObject(Class:="Outlook.Application")
If Err.Number = CANT_CREATE_OBJECT Then
Set ol = CreateObject(Class:="Outlook.Application")

I'll give it a whirl... but, I'm wondering if these are equivalent:

Set ol = CreateObject("Outlook.Application")
--and--
Set ol = CreateObject(Class:="Outlook.Application")

my guess is that they are

Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: MLH | last post by:
Is the following remotely correct? =DDE("C:\Program Files\Program Files\Outlook Express\OEmig50","Attachment","Name") I'm not sure that OEmig50.exe is the executable for OE. Anybody know? ...
10
by: John | last post by:
Hi When I open a new outlook email from vb.net, sometimes outlook is very slow to appear or occasionally outlook freezes completely. I am targeting mixed office2000/xp environments so I am...
14
by: Gerhard | last post by:
I'm posting this again, as no answer to the first post.... I would like to integrate Outlook into my vb.net web page, so that when I send an email (which I can successfully do now), it shows up...
26
by: Tom Becker | last post by:
Is there a way, from Access, to programmatically click the Send and Receive button in Outlook?
13
by: usenet | last post by:
How and where can one find out about the basics of VB/Access2003 syntax? I am a died in the wool C/C++/Java Linux/Unix programmer and I am finding it difficult to understand the program format...
1
by: =?Utf-8?B?cm9i?= | last post by:
C#.Net Outlook 2003 automation (programmatically) with Office.Interop.Outlook Problem: I have my outlook 2003 configured with multiple mailbox on my local machine. I want to specify the mailbox...
1
by: allbelonging | last post by:
C#.Net Outlook 2003 automation (programmatically) with Office.Interop.Outlook Problem: I have my outlook 2003 configured with multiple mailbox on my local machine. I want to specify the mailbox...
9
by: salad | last post by:
I have the following code. I have a reference to the Outlook library in the reference list. My machine is standalone, not on a network. Dim Olapp As Outlook.Application Set Olapp =...
0
by: madihamir | last post by:
Iam new to .net and have gotten assignment for make the class library to automate the outlook I have tried to done it but i've to make the Handlers also . Detecting an methods for receiving and...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
4
NeoPa
by: NeoPa | last post by:
Hello everyone. I find myself stuck trying to find the VBA way to get Access to create a PDF of the currently-selected (and open) object (Form or Report). I know it can be done by selecting :...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.