Closing Automation Object

S

S Jackson

I found this article: http://www.mvps.org/access/general/gen0017.htm

This is my code (which does not work for the moment):

Private Sub Command18_Click()
On Error GoTo Add_Err

'Exit procedure if Task already added to Outlook
If Me.AddedToOutlook = True Then
MsgBox "Task is already added to Outlook"

'Add Task

Else
Dim objOutlook As Object
Dim objTask As Object

Set objOutlook = CreateObject("Outlook.Application")
Set objTask = objOutlook.CreateItem(olTaskItem)

With objTask
.Subject = Me.CaseName & " / DHS No. " & Me.DHSNo
.DueDate = Me.Date
.Body = Me.Event
.ReminderSet = True

.Save
.Close
End With

'Release the TaskItem object variable
Set objTask = Nothing

End If

'Release the Outlook object variable
Set objOutlook = Nothing

'Set the AddedToOutlook flag, display a message
Me.AddedToOutlook = True
MsgBox "Task Added!"

Exit Sub
Add_Err:
MsgBox "Error" & Err.Number & vbCrLf & Err.Description
Exit Sub
End Sub

Am I understanding the article to state that I need to add: objOutlook.quit
before: Set objOutlook = Nothing ??

Can anyone confirm this? Thanks.
S. Jackson
 
S

S Jackson

Thanks Bruce!

Problem No. 1:
Can you tell why the code generates this error: Error438
Object doesn't support this property or method.

Problem No. 2:
If I set a reference to the Outlook library, the code works great, but I
want to avoid this as the users will be operating two different versions of
Outlook. But here is a new problem: when I run the code with a reference
set and early binding and Outlook is NOT already open, I get the following
message box:

The Reminder for "[Subject line of task]" will not appear because the item
is not in your Calendar or Task Folder. Is this ok?

If I run the code while Outlook if already open and running in the
background, it runs great.

How do I fix Problem No. 1?
Also, if I fix Problem No. 1 will Problem No. 2 come up? If so, how do I
fix that?

TIA

S. Jackson

Bruce M. Thompson said:
I found this article: http://www.mvps.org/access/general/gen0017.htm [...]
Am I understanding the article to state that I need to add: objOutlook.quit
before: Set objOutlook = Nothing ??

That is correct.
Can anyone confirm this? Thanks.

I think I just did. :)
 
B

Bruce M. Thompson

Problem No. 1:
Can you tell why the code generates this error: Error438
Object doesn't support this property or method.

Not knowing which line is generating this error, and not being intimately
familiar with the Outlook object model, I wouldn't dare venture a guess as to
the cause of that error, other than the possibility that it is related to your
use of an Outlook constant in your code (see my response to Problem 2 for more
on this). I do see a couple of errors in your code, however.
procedure.

.DueDate = Me.Date

.... is apt to be a problem, as "Date" is a function name - you can probably get
around it by enclosing "Date" with square brackets: Me.[Date]
"If...Then...End If" structure, so there will be times when you will be trying
to "Set" an object that hasn't been declared (from your code):

'***
End If

'Release the Outlook object variable
Set objOutlook = Nothing
'***
binding and application constants, in case you were having problems with that
approach.
Problem No. 2:
If I set a reference to the Outlook library, the code works great, but I
want to avoid this as the users will be operating two different versions of
Outlook. But here is a new problem: when I run the code with a reference
set and early binding and Outlook is NOT already open, I get the following
message box:

The Reminder for "[Subject line of task]" will not appear because the item
is not in your Calendar or Task Folder. Is this ok?

If I run the code while Outlook if already open and running in the
background, it runs great.

What happens when you set no reference and use late binding (late binding
appears to be what you are doing in your code, anyway)? Note: You cannot use the
Outlook constants when late binding unless you declare and assign values to them
inside of Access (in the procedure or a global module), as they won't be
available to the procedure otherwise.

For more information on late binding, see the following page at Tony Toews' web
site:

Late Binding in Microsoft Access
http://www.granite.ab.ca/access/latebinding.htm

If you are writing your code on a machine with the earliest version of Outlook
that will be used by those to whom the application will be deployed, you
shouldn't have a problem with early binding. It's been my experience that the
presence of a later version of Outlook will merely cause the library reference
to be automatically updated to the later version.
 
S

S Jackson

Well Bruce, thanks for trying to help me. Unfortunately, I am just not
getting it as I do not have enough experience with coding. Thank you for
pointing out the "Date" issue. I missed that one as someone else had
created that.

I am pretty frustrated right now because according to what Dan posted below,
my code should work the way its written.
Dan Wrote:

All you have to do is Dim the variables as Object.

Dim objOutlook As Object
Dim objTask As Object

Any objects that you create yourself, use CreateObject, as you have done.
The TaskItem object is created by your Outlook Application variable so
you don't have to worry about that one

Anymore thoughts on this one? Or should I just give up and go home (argh!)
BTW, I wished I could use early binding but unfortunately, I am using Office
2000 and some of the users will be using all different versions of office,
including Office 97, which reminds me that I still need to somehow convert
my db backward to Office 97 which I know now (too late) is going to be a
problem. Could I install Office 97 on my machine without messing up Office
2000? Would I be able to have both versions of Office installed and still
have access to the '97 object libraries that I need to reference in the db?

S. Jackson

Note Dan said something about Outlook creating
Bruce M. Thompson said:
Problem No. 1:
Can you tell why the code generates this error: Error438
Object doesn't support this property or method.

Not knowing which line is generating this error, and not being intimately
familiar with the Outlook object model, I wouldn't dare venture a guess as to
the cause of that error, other than the possibility that it is related to your
use of an Outlook constant in your code (see my response to Problem 2 for more
on this). I do see a couple of errors in your code, however.
the
procedure.

.DueDate = Me.Date

... is apt to be a problem, as "Date" is a function name - you can probably get
around it by enclosing "Date" with square brackets: Me.[Date]
"If...Then...End If" structure, so there will be times when you will be trying
to "Set" an object that hasn't been declared (from your code):

'***
End If

'Release the Outlook object variable
Set objOutlook = Nothing
'***
binding and application constants, in case you were having problems with that
approach.

Problem No. 2:
If I set a reference to the Outlook library, the code works great, but I
want to avoid this as the users will be operating two different versions of
Outlook. But here is a new problem: when I run the code with a reference
set and early binding and Outlook is NOT already open, I get the following
message box:

The Reminder for "[Subject line of task]" will not appear because the item
is not in your Calendar or Task Folder. Is this ok?

If I run the code while Outlook if already open and running in the
background, it runs great.

What happens when you set no reference and use late binding (late binding
appears to be what you are doing in your code, anyway)? Note: You cannot use the
Outlook constants when late binding unless you declare and assign values to them
inside of Access (in the procedure or a global module), as they won't be
available to the procedure otherwise.

For more information on late binding, see the following page at Tony Toews' web
site:

Late Binding in Microsoft Access
http://www.granite.ab.ca/access/latebinding.htm

If you are writing your code on a machine with the earliest version of Outlook
that will be used by those to whom the application will be deployed, you
shouldn't have a problem with early binding. It's been my experience that the
presence of a later version of Outlook will merely cause the library reference
to be automatically updated to the later version.
 
B

Bruce M. Thompson

Well Bruce, thanks for trying to help me. Unfortunately, I am just not
getting it as I do not have enough experience with coding. Thank you for
pointing out the "Date" issue. I missed that one as someone else had
created that.

No problem.
I am pretty frustrated right now because according to what Dan posted below,
my code should work the way its written.
Dan Wrote:

All you have to do is Dim the variables as Object.

Dim objOutlook As Object
Dim objTask As Object

Any objects that you create yourself, use CreateObject, as you have done.
The TaskItem object is created by your Outlook Application variable so
you don't have to worry about that one

Anymore thoughts on this one?

Dan is absolutely correct and your original code in this thread already
incorporated this approach. I pointed out, however, as has Dan, that you can't
use the Outlook application's intrinsic constants (specific reference is made to
"olTaskItem"), so you need to either use the numeric value represented by that
constant or declare a constant in the Access application and assign that numeric
value to it (you can name it "olTaskItem").

'In the procedure
Const olTaskItem = 3

.... or ...

'In a global module
Global Const olTaskItem = 3
Or should I just give up and go home (argh!)

Well said:
BTW, I wished I could use early binding but unfortunately, I am using Office
2000 and some of the users will be using all different versions of office,
including Office 97, which reminds me that I still need to somehow convert
my db backward to Office 97 which I know now (too late) is going to be a
problem. Could I install Office 97 on my machine without messing up Office
2000? Would I be able to have both versions of Office installed and still
have access to the '97 object libraries that I need to reference in the db?

See:

ACC2000: How to Install Access 97 and Access 2000 on the Same Computer
http://support.microsoft.com/default.aspx?kbid=241141
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top