Executive a Module with a Command Button


L

Larry

I'm trying to create a Command Button using a Module that
when click will open up Outlook and populate the To and
Subject Field.

Public Function SendOutlookMsg(strSubject As String, strTo
As String, strHTML As String, Optional intUseBCC As
Integer = 0) As Integer
' Function to send an email message using Outlook
' Inputs: Subject of the message
' List of valid "To" email addresses
' HTML for the body of the message
' Send using BCC flag (optional)
' Output: True if successful

Dim objOL As Object, ObjMail As Object

'Get a pointer to Outlook - late binding
SetobjOl = CreateObject("Outlook.Application")
' Create new email
Set ObjMail = objOL.CreateItem(olMailItem)
' Set the subject
If intUseBCC = True Then
ObjMail.BCC = strTo
Else
ObjMail.To = strTo
End If
' Insert the HTML of the message
ObjMail.HTMLbody = strHTML
' Display it
ObjMail.Display
' Done - clear objects
Set ObjMail = Nothing
Set objOL = Nothing
' Return True
SendOutlookMsg = True

SendOutlookMsg_Exit:
Exit Function

End Function

How do I get this to work?

Thanks,
Michelle
 
Ad

Advertisements

A

Alex Dybenko

you have to add a command button on a form, go to it click event procedure
and write there:

SendOutlookMsg me.txtSubject & "", me.txtTo & "", me.txtBody & ""

just replace txtSubject, txtTo, txtBody with correct names of controls on
your form
 

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