Late Binding when sending a message

G

Gina

I have been battling with this problem for a long time. Please get me out
of my misery!!!

Late Binding. there doesn't seem to be lot of information on the subject.

I need to send emails, tasks, contacts to outlook from MS Access using Late
Binding because of a compatibility issue with Outlook I cannot put any
Outlook references.

Can somebody please correct me.


Dim objOutlook As Object
Dim objMsg As Object
Dim objRecip As Object
Dim objAttach As Object

Set objOutlook = CreateObject("Outlook.Application")
Set objMsg = objOutlook.CreateItem(olMailItem)

With objMsg
Set objRecip = .Recipients.Add("Jo Blo")
objRecip.Type = olTo

.Subject = "Help me Please"
.Body = "Late Binding is harder than it sounds"

If Not IsMissing("C:\Hello.txt") Then
Set objAttach = .Attachments.Add("C:\Hello.txt")
End If

.Send

End With
Set objMsg = Nothing
Set objOutlook = Nothing
 
D

Douglas J. Steele

I assume the specific problem you're having is with the line

Set objMsg = objOutlook.CreateItem(olMailItem)

That's because olMailItem is a constant whose value is stored in the Outlook
reference. Without setting the reference, Access doesn't know what that
value is.

While you're developing, add the reference in. When you've got the
reference, go to the Debug window and type

?olMailItem

That'll return the value of the constant. Remove the reference, and either
create your own global constant with that value, or replace every usage of
the constant with the actual value. My recommendation would be the former.
You may want to rename the constant slightly (say gc_olMailItem) to make it
easier to tell it's your constant, not an intrinsic one, but to still make
it easy to tell where the constant is coming from.

You'll be able to find all of these constants by compiling your code. Access
will stop at each undefined constant.
 
T

Tony Toews

Gina said:
Late Binding. there doesn't seem to be lot of information on the subject.

Doug has given you an excellent answer which showed me I needed to do
a small update to my page. Thanks Doug.

See the Late Binding page at my website.

Tony
--
Tony Toews, Microsoft Access MVP
Please respond only in the newsgroups so that others can
read the entire thread of messages.
Microsoft Access Links, Hints, Tips & Accounting Systems at
http://www.granite.ab.ca/accsmstr.htm
 

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