Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Another Outlook query!

Status
Not open for further replies.

rookery

Programmer
Apr 4, 2002
384
GB
OK this isnt a seasy as it looks! I've checked out the FAQ sections but I still cant figure out why the following code doesnt work:

Private Sub cmdEmail_Click()

Dim olookApp As Outlook.Application
Dim olookMsg As Outlook.MailItem
Dim olookRecipient As Outlook.recipient

'create the outlook session
Set olookApp = CreateObject("Outlook.Application")

'create the message
Set olookMsg = olookApp.CreateItem(olMailItem)

With olookMsg

' put in the adressee
Set olookRecipient = .Recipients.Add("fred.bloggs@bloggs.com")
olookRecipient.Type = olTo
.subject = "This is a test!"
.body = "Cant promise this will be the last test! The first of many!" & vbCrLf
.Display

End With

End Sub

I have checked the MS Outlook 9.0 Reference. Does it's priority matter? When I tried declaring objects in the parenthesis after the "Private Sub" etc and then tried opening the Form I was prompted to enter a parameter. Any ideas...?
 
Try replacing

Set olookRecipient = .Recipients.Add("fred.bloggs@bloggs.com")
olookRecipient.Type = olTo

With

.To = "fred.bloggs@bloggs.com"

Which would mean you don't need
Dim olookRecipient As Outlook.recipient

Try that and let me know... Kyle [pc1]
 
Kyle

Thanks for your reply. I tried what you suggested but it is still falling over before it reaches that code. I'm getting a run time error 429:

"ActiveX component cant create object"

message on the following line:

Set olookApp = CreateObject("Outlook.Application")

To reiterate I have checked the Outlook reference already. Any ideas...?
 
Hi there:

Try this. I'm doing something similar to this.

Set olookMsg = olookapp.CreateItem(olMailItem)

This works for me.

Shawn
 
Hi Shawn

Thanks for your reply. I already have this code within my program. I wondered if you meant that I didnt need to use the line:

Set olookApp = CreateObject("Outlook.Application")

but when I removed it I got a Run Time Error 91 "Object Variable Not Set".

I have declared olookMsg. Puzzling eh... Are you using Access2K? What references have you got checked? I'm also using Outlook Express v.5. Would that have anything to do with it? Anymore for anymore....
 
i would thtink that the outlook express is the problem... it's very limited in what it can do, and the call to OUTLOOK in code looks for the full vertion of outlook... not outlook express... look in help files to see if you can call outlook express...

--Junior JHauge@jmjpc.net
Life is change. To deny change is to deny life.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top