Issue with Code "SendObject"

P

Peter

Private Sub Command36_Click()
On Error GoTo Error_Handler

DoCmd.SendObject

Dim varTo As Variant
Dim varCC As Variant
Dim stSubject As String

Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
Dim errLoop As Error

Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)

With objEmail
..To = Me.[Text28]
..CC = Me.[Text30]
..Subject = Me.[Text34]

End With

Exit_Here:
Set objOutlook = Nothing
Exit Sub

Error_Handler:
MsgBox Err & ": " & Err.Description
Resume Exit_Here

End Sub
 
D

Daniel Pineault

What is your question?


I see you are mixing Outlook Automation with the SendObject Method?! This
will not work! You need to use either

Docmd.SendObject(....)

or

Dim varTo As Variant
Dim varCC As Variant
Dim stSubject As String

Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
Dim errLoop As Error

Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)

With objEmail
..To = Me.[Text28]
..CC = Me.[Text30]
..Subject = Me.[Text34]

End With

Exit_Here:
Set objOutlook = Nothing


You also need to add proper error handling to your procedure. Take a look
at http://www.devhut.net/index.php?lang=en&pid=0000000013#OutlookAuto

If you are sending an e-mail without any attachments and no access object,
so just a message, the SendObject is the tool for the job

DoCmd.SendObject acSendNoObject,,,Me.[Text28],Me.[Text30],,Me.[Text34],"Your
Message Goes Here",True
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.
 
P

Peter

Thank you for your mind reading ability Daniel, precisely what i need to know..

Once again thanks!


Daniel Pineault said:
What is your question?


I see you are mixing Outlook Automation with the SendObject Method?! This
will not work! You need to use either

Docmd.SendObject(....)

or

Dim varTo As Variant
Dim varCC As Variant
Dim stSubject As String

Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
Dim errLoop As Error

Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)

With objEmail
.To = Me.[Text28]
.CC = Me.[Text30]
.Subject = Me.[Text34]

End With

Exit_Here:
Set objOutlook = Nothing


You also need to add proper error handling to your procedure. Take a look
at http://www.devhut.net/index.php?lang=en&pid=0000000013#OutlookAuto

If you are sending an e-mail without any attachments and no access object,
so just a message, the SendObject is the tool for the job

DoCmd.SendObject acSendNoObject,,,Me.[Text28],Me.[Text30],,Me.[Text34],"Your
Message Goes Here",True
--
Hope this helps,

Daniel Pineault
http://www.cardaconsultants.com/
For Access Tips and Examples: http://www.devhut.net
Please rate this post using the vote buttons if it was helpful.



Peter said:
Private Sub Command36_Click()
On Error GoTo Error_Handler

DoCmd.SendObject

Dim varTo As Variant
Dim varCC As Variant
Dim stSubject As String

Dim objOutlook As Outlook.Application
Dim objEmail As Outlook.MailItem
Dim errLoop As Error

Set objOutlook = CreateObject("Outlook.application")
Set objEmail = objOutlook.CreateItem(olMailItem)

With objEmail
.To = Me.[Text28]
.CC = Me.[Text30]
.Subject = Me.[Text34]

End With

Exit_Here:
Set objOutlook = Nothing
Exit Sub

Error_Handler:
MsgBox Err & ": " & Err.Description
Resume Exit_Here

End Sub
 

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