Results 1 to 10 of 10
  1. #1
    jj1 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    128

    Automatic Email if combo box's 2nd value is selected as first is yes and 2nd is no

    Can anybody help with the code to send automatic email if combo box's 2nd value is selected for example if first value is "yes" and 2nd is "no". And also I want to send email to three people if 2nd value in the combo box of a form is selected


    Private Sub cmdSend_Click()
    Dim rst As DAO.Recordset
    Dim db As DAO.Database
    Dim appOutLook As Outlook.Application
    Dim MailOutLook As Outlook.MailItem




    Set appOutLook = CreateObject("Outlook.Application")
    Set MailOutLook = appOutLook.CreateItem(olMailItem)


    'Set rst = db.OpenRecordset("SELECT * FROM tUsers WHERE ID=1")


    Set appOutLook = CreateObject("Outlook.Application")
    Set MailOutLook = appOutLook.CreateItem(olMailItem)
    With MailOutLook
    .To = rst!Email
    .Subject = "Testing"
    .Body = "Test number one"
    .Send
    rst.Close
    Set rst = Nothing
    Set db = Nothing
    End With
    End Sub


    I have this code

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    You mean if they change the value from yes to no? You could use the before update event of the combo and compare the Value and OldValue properties.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    jj1 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    128
    Private Sub Status_AfterUpdate()




    Dim appOutLook As Outlook.Application
    Dim MailOutLook As Outlook.MailItem
    Dim SQL As String
    Dim ManagerEmail As String


    Set appOutLook = CreateObject("Outlook.Application")
    Set MailOutLook = appOutLook.CreateItem(olMailItem)



    SQL = ("SELECT ManagerEmail FROM ManagerEmailAddress Where atnStatusID = 2")



    Set appOutLook = CreateObject("Outlook.Application")
    Set MailOutLook = appOutLook.CreateItem(olMailItem)
    With MailOutLook

    .To = (ManagerEmail)
    .Subject = "Testing"
    .Body = "Test number one"


    Set db = Nothing
    End With
    End Sub


    This is what I am trying to do. Can anybody check. where I am wrong it's not sending the email

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Well, it's not sending because you didn't include

    .Send

    or

    .Display

    You didn't do anything with the SQL, and didn't set ManagerEmail, and double set the Outlook objects.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    jj1 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    128
    Thanks for your reply. It's now sending email. What should I do for SQL and ManagerEmail

    What I am trying to do is IF on the form's combo box have 2 values say Yes or No. and only if somebody selects No then sends an email to 3 specific managers

    So I was trying to write the SQl as SELECT ManagerEmailaddress FROM TblManagerEmailAddress where value in combo box is selecected as No.

    How should I write query

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    You need to do what you were doing in the first post; open a recordset on the SQL and use the recordset value. Alternatively you could use a DLookup().
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    jj1 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    128
    Can you check what I am doing wrong with this one

    Private Sub Status_AfterUpdate()


    Dim db As Database
    Dim rs As dao.Recordset
    Dim appOutLook As Outlook.Application
    Dim MailOutLook As Outlook.MailItem
    Dim SQL As String
    Dim ManagerEmail As String


    ' Dim st As String




    Set db = CurrentDb
    Set rs = CurrentDb.OpenRecordset("SELECT * FROM ManagerEmailAddress WHERE SentEmailorNot=True")


    Set appOutLook = CreateObject("Outlook.Application")
    Set MailOutLook = appOutLook.CreateItem(olMailItem)


    rs.MoveFirst
    While Not rs.EOF


    rs.MoveNext
    Wend




    ' SQL = "SELECT ManagerEmailAddress.ManagerEmail FROM ManagerEmailAddress"




    With MailOutLook
    'MailOutLook.To = rs!ManagerEmail
    .To = "rs!ManagerEmail"
    .sUBJECT = "Testing"
    .Body = "Test number one"
    MailOutLook.Send
    ' MailOutLook.Quit


    rs.Close
    db.Close




    Set rs = Nothing
    Set db = Nothing
    End With


    End Sub
    Quote Originally Posted by pbaldy View Post
    You need to do what you were doing in the first post; open a recordset on the SQL and use the recordset value. Alternatively you could use a DLookup().

  8. #8
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    What specific problem are you having? You're not doing anything in the loop, and the email address reference shouldn't be in quotes.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    jj1 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    May 2014
    Posts
    128
    Its giving me error 424

    .To = rs!ManagerEmail

  10. #10
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    With the loop above you've moved recordset past the last record. I would expect code inside the loop, not after.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

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

Similar Threads

  1. Replies: 1
    Last Post: 12-22-2014, 09:21 PM
  2. problem: automatic send email on query
    By ihere in forum Import/Export Data
    Replies: 12
    Last Post: 05-18-2014, 03:38 PM
  3. Replies: 3
    Last Post: 01-31-2014, 04:34 PM
  4. Send automatic email alerts from access
    By RERM in forum Programming
    Replies: 5
    Last Post: 09-03-2013, 03:49 PM
  5. Automatic Email
    By Peacekeeper in forum Access
    Replies: 8
    Last Post: 11-03-2011, 10:55 AM

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