Results 1 to 4 of 4
  1. #1
    LukeSept is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Oct 2015
    Location
    Norway
    Posts
    6

    Sending different emails based on checkbox selection


    Hi, I'm making autorespons in my form. I have already an VBA code to send an email from access using CDO. What I wish to do now is have this mail send diferent statement based on checkbox selection. For example I have an list of products an checkbox next to each product and a send email button. If I press a button without marking any of the checkboxes i send an email with message "I'm so sexy" if i mark any of the checkboxes i get an message "checked produt name" is so sexy.

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Need VBA code that loops through the dataset. Fairly common topic. Here is a start https://www.accessforums.net/program...ook-21903.html
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    LukeSept is offline Novice
    Windows 8 Access 2010 64bit
    Join Date
    Oct 2015
    Location
    Norway
    Posts
    6
    Can't it be done with using for example If ?

    Public Function send_email()


    Set cdomsg = CreateObject("CDO.message")
    With cdomsg.Configuration.Fields
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2 'NTLM method
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
    .Item("http://schemas.microsoft.com/cdo/configuration/smptserverport") = 587
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = True
    .Item("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
    .Item("http://schemas.microsoft.com/cdo/configuration/sendusername") = "test@gmail.com"
    .Item("http://schemas.microsoft.com/cdo/configuration/sendpassword") = "test"
    .Update
    End With

    ' build email parts
    With cdomsg
    .To = "smb@yahoo.com"
    .From = "smb@gmail.com"
    .Subject = "Facepalm"

    ' I put txtCount for counting all the records with selected checkbox fields, since there are only 2 possible outcoms either none of the checkboxes are selected or at least one is.
    If Me!txtCount = 0 Then
    .TextBody = "Love facepalming. Its awesome"
    Else
    .TextBody = "I hate you" & RecordName
    End If


    .Send
    End With
    Set cdomsg = Nothing
    End Function

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,772
    Yes, can dynamically construct body with conditional.

    What is RecordName?

    Where is the code that loops through records?

    Did you test code?
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Print report based on the checkbox selection
    By LukeSept in forum Access
    Replies: 4
    Last Post: 10-19-2015, 11:34 PM
  2. Replies: 2
    Last Post: 10-28-2014, 03:55 AM
  3. Sending Emails and VBA coding
    By lucy1216 in forum Programming
    Replies: 4
    Last Post: 05-20-2013, 05:57 AM
  4. Replies: 3
    Last Post: 10-31-2011, 04:54 PM
  5. Sending multiple emails
    By Petefured in forum Programming
    Replies: 0
    Last Post: 05-24-2011, 03:40 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums