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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Send email from a form with 2 different forms

Status
Not open for further replies.

acnovice

Programmer
Jan 27, 2005
100
US
Hi,

I created VBA code to send email from a form. This code opens outlook that let us edit the form before out.

Question -- I want to use 2 different forms to send out email in the Body section. The 2 forms are almost same but sometimes I want to add one sentence for greeting but sometimes it doesn't need.

How and where do I change the code ?
Here are my code that I'm using.

Private Sub cmdSendEmail_Click()
On Error GoTo Err_cmdSendEmail_Click

Dim strEmail, strBody As String
Dim objOutlook As Outlook.Application
Dim objFolder As Outlook.MAPIFolder

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

strBody = strBody & "Dear " & dName & "," & Chr(13) & Chr(13)
strBody = strBody & "Inquiry No.: " & "Q" & " " & QNo & Chr(13) & Chr(13)
strBody = strBody & " Form Factor: " & ProducType & Chr(13)
strBody = strBody & " Input: " & inpuType & Chr(13)
strBody = strBody & " Output: " & Output & Chr(13)
strBody = strBody & " Dimensions: " & Dimension & Chr(13)
..............
..............

With objEmail
.Subject = "Q " & QNo & " " & Title
.Body = strBody
End With

Set objEmail = Nothing

Exit_cmdSendEmail_Click:
Exit Sub

Err_cmdSendEmail_Click:
MsgBox Err.Description
Resume Exit_cmdSendEmail_Click

End Sub
 
Hello, there are any number of ways to accomplish this. One of the easiest might be including a check box to distinguish between the two forms - call it ckInclude. If it is checked, use one string. If not, use another.

Select case ckInclude
Case is = -1 'Checked
strBody = strBody & "Dear " & dName & "," & Chr(13) & Chr(13)
strBody = strBody & "Inquiry No.: " & "Q" & " " & QNo & Chr(13) & Chr(13)
strBody = strBody & " Form Factor: " & ProducType & Chr(13)
strBody = strBody & " Input: " & inpuType & Chr(13)
strBody = strBody & " Output: " & Output & Chr(13)
strBody = strBody & " Dimensions: " & Dimension & Chr(13)

case else: 'Unchecked
'Use another string.

end select

..............
With objEmail
.Subject = "Q " & QNo & " " & Title
.Body = strBody
End With
 

Thank you dRahme.
It's so simple and perfect. It works well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top