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

Using Command Button to Send E-mail 1

Status
Not open for further replies.

TechieJr

Instructor
Nov 13, 2002
71
CA
Hello All,

I have been trying to get a command button to send an email based on modified code from thread 702-396121 and am stuck.

I have a button on a subform which initiates data collection from both the subform and the parent form. It then starts an Outlook e-mail in which the user can fill in the e-mail addresses of the recipient and cc recipient.

My problem comes in a If .. Then .. Else portion which chooses the Subject line based on a radio button selection of an option group. I keep receiving a compilation error "Else without If" yet cannot see a problem. Can anyone out there help?

Thanks a bunch
TechieJr.

PS. Let me know what part of my script I need to explain to help you troubleshoot it.

Code:
 Private Sub Command47_Click()
    Dim CallerName As String, Comp As String, BusPh As String, Called As String, _
    contype As String, FolUp As String, Note As String
    Dim objOutlook As Outlook.Application
    Dim objEmail As Outlook.MailItem
        
    CallerName = Forms![f_daylogentry]!Combo10
    Comp = Forms![f_daylogentry]!Company
    BusPh = Forms![f_daylogentry]!BusPhone
    Called = Me!CalledFor
    Note = Me!Comments
    
    If Me!ContactType = "3" Then contype = "Visitor came to see "
    Else
        contype = "Phone Call for "
    End If
    
    If Me!Action = "4" Then FolUp = "Returned your call."
    ElseIf Me!Action = "3" Then FolUp = "Will call back."
    Else
        FolUp = "Please call."
    End If
    
    Set objOutlook = CreateObject("Outlook.application")
    Set objEmail = objOutlook.CreateItem(olMailItem)
        
    With objEmail
        .Subject = contype & " " & Called
        .Body = CallerName & " of " & Comp & " (" & BusPh & ") " & Chr(13)
        .Body = Body & FolUp & Chr(13)
        .Body = Body & Note
        .Display
    End With
    
    Set objEmail = Nothing
    
End Sub
 
Hi,

Have you tried using a case statement? Try this:

Select Case Me!ContactType
Case 3
contype = "Visitor came to see "
Case Else
contype = "Phone Call for "
End Select

Select Case Me!Action
Case 4
FolUp = "Returned your call."
Case 3
FolUp = "Will call back."
Case Else
FolUp = "Please call."
End Select

I have found that case statements are better to use in situations like yours than an If...Then...Statement

HTH,

jbehrne

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

With objEmail
.Subject = contype & " " & Called
.Body = CallerName & " of " & Comp & " (" & BusPh & ") " & Chr(13)
.Body = Body & FolUp & Chr(13)
.Body = Body & Note
.Display
End With
If at first you don't succeed, call in an airstrike. - Murphy's Laws of Combat Operations
 
Good Morning jbehrne,

Yours was a good message to wake up to, as it works wonderfully. I will have to remember to use the "Select Case" command more. Gave you a star for this. Hope it helps start your weekend well.

Cheers,

TechieJr.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top