Editing sendmail function

lxdawg25

New Member
Joined
Aug 13, 2007
Messages
4
Okay so I have a user form and when I click okay and I want it to send an email to the people whos chkboxes = true and I want it to contain a message body that is dependent on water quality varibles chkboxes = true
not included in this code is the cmdOk_Click() which will call the email function. Here is the userform code.

Code:
Private Sub cmdCancel_Click()

    Unload Me

End Sub

Private Sub UserForm_Initialize()

    Select Case frmOtter.txtPh
    
        Case 0 To 8#
            
            chkPh = True
            
        Case 8.5 To 100
        
            chkPh = True
            
        Case Else
        
            chkPh = False
            
     End Select
     
     Select Case frmOtter.txtNh3
    
        Case 0.1 To 100
            
            chkNh3 = True
                       
        Case Else
        
            chkNh3 = False
            
     End Select
     
     Select Case frmOtter.txtSal
    
        Case 0 To 27
            
            chkSal = True
                       
        Case 36 To 1000
        
            chkSal = True
                       
        Case Else
        
            chkSal = False
            
     End Select
     
     Select Case frmOtter.txtNo3
    
        Case 35 To 10000
            
            chkNo3 = True
                       
        Case Else
        
            chkNo3 = False
            
     End Select
     
     If frmOtter.txtNo3.Value = "over" Then
     
        chkNo3 = True
        
        Else
        
        If frmOtter.txtNo3.Value = "35+" Then
        
        chkNo3 = True
        
        Else
        
        chkNo3 = False
        
        End If
        
    End If
     
     Select Case frmOtter.txtWtemp
    
        Case 0 To 47
            
            chkWtemp = True
                       
        Case 60 To 510
        
            chkWtemp = True
            
        Case Else
        
            chkWtemp = False
            
     End Select
     
     Select Case frmOtter.txtCl
    
        Case 0.1 To 100
            
            chkCl = True
                       
        Case Else
        
            chkCl = False
            
     End Select
     
     Select Case frmOtter.txtAlk
    
        Case 0 To 150
            
            chkAlk = True
                       
        Case 250 To 1000
            
            chkAlk = True
                       
        Case Else
        
            chkAlk = False
            
     End Select

    chkAtemp = False
    chkNo2 = False
    chkColi = False
    chkOrp = False
    
    chkbjohnsons = False
    chkClobue = False
    chkDbrandt = False
    chkEhuber = False
    chkEporter = False
    chkGanderson = False
    chkJrarnold = False
    chkJohnHewitt = False
    chkKgrzenda = False
    chkLripley = False
    chkLewinger = False
    chkMkelley = True
    chkNhardy = False
    chkPbeaven = False
    chkRtoth = False
    chkSalbes = False
    chkTdyer = False
    
End Sub

here is the code for the sendmail function

Code:
Sub Mail_small_Text_Outlook()
' Is working in Office 2000-2007
    Dim OutApp As Object
    Dim OutMail As Object
    Dim strbody As String
 
    Set OutApp = CreateObject("Outlook.Application")
    OutApp.Session.Logon
    Set OutMail = OutApp.CreateItem(0)
 
    strbody = "Greg" & vbNewLine & vbNewLine & _
              "This is an automated message to let you know that on" & vbNewLine & _
              Format(Date, "Short Date") & vbNewLine & _
              "Sea Otters pH is " & ActiveCell.Value & vbNewLine & _
              "This is just a warning message so that the proper steps can be taken" & vbNewLine & _
              "Please feel free to let life Support know if we can be of any assistance" & vbNewLine & vbNewLine & _
              vbNewLine & _
              "Thank You," & vbNewLine & _
              "Life Support"

    On Error Resume Next
    With OutMail
        .To = "lxdawg25@gmail.com"
        .CC = ""
        .BCC = ""
        .Subject = "A Message from your friendly Life Support Staff"
        .Body = strbody
        .Send   'or use .Display
    End With
    On Error GoTo 0
 
    Set OutMail = Nothing
    Set OutApp = Nothing
End Sub

Again I don't know how to make the strbody take if statements or what but I also don't know how to change the .to line to be varible. Any help would be greatly greatly appreciated.

Greg
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
The .To line currently uses " around the email address if you push the email address into a variable the just have it work as

Code:
.To = EmailList

Depending on if you want an individual email to each person or a group email. If a group then seperate email addresses with ;
If individual ones then have it check if the box is ticked if so push that email to the variable and send then check the next box etc

something like
Code:
Dim cCont As Control, EmailList As String
For Each cCont In Me.Controls
    If cCont.Name = "chkbjohnsons" Then 
        If cCont = True Then
             EmailList = "bjohnsons@false-email.com"
        Else Next cCont
        End If
    End If

' ###############
' do this for every email
' ###############

' add email code here

Next cCont
 
Upvote 0
Thank you so much for your reply I am still having a bit of trouble though

I want to do this as one group email if possible and I'm having a bit of trouble understanding how to use what you gave me to do that. I understand how to have it send out individual emails that way, but is there anyway that I can get it to do this as a single email to multiple people?

Thank you again

Greg
 
Upvote 0
Again you need to use the line
Code:
.To = EmailList

Then try something like this
Code:
Dim cCont As Control, EmailList As String 
EmailList = ""
For Each cCont In Me.Controls 
    If cCont.Name = "chkbjohnsons" Then 
        If cCont = True Then 
             EmailList = EmailList & "bjohnsons@false-email.com" & "; "
        Else Next cCont 
        End If 
    End If 

' ############### 
' do this for every email 
' ############### 
Next cCont 


' add email code here

Hopefully that should do it
 
Upvote 0
Great!! I'll try this now, I didn't know I could to use emaillist &... to make the varible work like that.

Thank you again

Greg
 
Upvote 0

Forum statistics

Threads
1,214,782
Messages
6,121,532
Members
449,037
Latest member
tmmotairi

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top