PDA

View Full Version : Function Module (Display and Send)



gvreddyhr
10-30-2011, 12:52 AM
HI,

Thank you all for your valuable inputs, I wanted to include one command in below programme, when I enter “Display” in my input box, mail should generate and display, if I give command as “Send” email should automatically send without popping up, everything works fine if I enter “.Display” and “.send” in the place where I keyed in Myinput, but am not able to use this with input box, can anyone suggest me where am I going wrong.

Thanks


Function GVR_Mail_PDF_Outlook(FileNamePDF As String, StrTo As String, _
StrSubject As String, StrBody As String, Send As Boolean)
Dim OutApp As Object
Dim OutMail As Object
Dim MyInput
MyInput = InputBox("Enter the Mode of communication (Display or Send)")

Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)

On Error Resume Next
With OutMail
.To = StrTo
.CC = ""
.BCC = ""
.Subject = StrSubject
.Body = StrBody
.Attachments.Add FileNamePDF
If Send = True Then
.Send
Else
.MyInput
End If
End With
On Error GoTo 0

Set OutMail = Nothing
Set OutApp = Nothing
End Function

Kenneth Hobs
10-30-2011, 09:20 PM
Why do you need to show a MsgBox? The code that calls the Function can set the Send boolean value as needed.

Function GVR_Mail_PDF_Outlook(FileNamePDF As String, StrTo As String, _
StrSubject As String, StrBody As String, Send As Boolean)
Dim OutApp As Object
Dim OutMail As Object
Set OutApp = CreateObject("Outlook.Application")
Set OutMail = OutApp.CreateItem(0)
On Error Resume Next
With OutMail
.To = StrTo
.CC = ""
.BCC = ""
.Subject = StrSubject
.Body = StrBody
.Attachments.Add FileNamePDF
If Send Then
.Send Else
.Display
End If
End With
On Error Goto 0
Set OutMail = Nothing
Set OutApp = Nothing
End Function

mikerickson
10-30-2011, 11:24 PM
Is this the same problem as in
http://www.vbaexpress.com/forum/showthread.php?t=39614 ?

Please don't start multiple threads on the same problem.