Results 1 to 2 of 2
  1. #1
    lucy1216 is offline Novice
    Windows XP Access 2003
    Join Date
    Sep 2010
    Posts
    10

    Where do I put an update command in the following email loop

    Private Sub cmdEmailConfirmed_Click()
    Dim rst As DAO.Recordset
    Dim db As DAO.Database
    Dim oOApp_001 As Outlook.Application
    Dim oOMail_001 As Outlook.MailItem
    Dim distro As String
    Dim strSql As String
    Set db = CurrentDb()
    'Sets the email distro and subject line to blank
    distro = ""
    Set oOApp_001 = CreateObject("Outlook.Application")
    Set oOMail_001 = oOApp_001.CreateItem(olMailItem)

    strSql = "SELECT tblReceiveTemp.ATTReceiveStatus, tblReceiveTemp.SprintReceiveStatus, tblReceiveTemp.VerizonReceiveStatus, tblReceiveTemp.[Level 1Approver Email], tblReceiveTemp.[Level 1Approver]" & _
    " FROM tblReceiveTemp " & _
    " WHERE tblReceiveTemp.ATTReceiveStatus = 'NR'OR tblReceiveTemp.SprintReceiveStatus = 'NR' OR tblReceiveTemp.VerizonReceiveStatus = 'NR'"
    Set rst = db.OpenRecordset(strSql, dbOpenDynaset)
    'If recordset is empty, exit
    Do While Not rst.EOF
    distro = distro & ";" & rst.Fields("[Level 1Approver Email]")

    rst.MoveNext
    Loop
    With oOMail_001
    'now use the variable disto with all the email names in the to field of outlook


    '.CC =
    .BCC = distro
    .Subject = "Wireless Telecommunication Approval - Reminder"
    .Body = "Body"
    .display
    .BodyFormat = 1
    End With
    rst.Close
    Set rst = Nothing
    Set db = Nothing
    End Sub
    Private Sub cmdEmailConfirmed2_Click()
    Dim rst As DAO.Recordset
    Dim db As DAO.Database
    Dim oOApp_001 As Outlook.Application
    Dim oOMail_001 As Outlook.MailItem
    Dim distro As String
    Dim strSql As String
    Set db = CurrentDb()
    'Sets the email distro and subject line to blank
    distro = ""
    Set oOApp_001 = CreateObject("Outlook.Application")
    Set oOMail_001 = oOApp_001.CreateItem(olMailItem)

    strSql = "SELECT tblReceiveTemp.ATTReceiveStatus, tblReceiveTemp.SprintReceiveStatus, tblReceiveTemp.VerizonReceiveStatus, tblReceiveTemp.[Level 1Approver Email], tblReceiveTemp.[Level 1Approver]" & _
    " FROM tblReceiveTemp " & _
    " WHERE tblReceiveTemp.ATTReceiveStatus = 'NR'OR tblReceiveTemp.SprintReceiveStatus = 'NR' OR tblReceiveTemp.VerizonReceiveStatus = 'NR'"
    Set rst = db.OpenRecordset(strSql, dbOpenDynaset)
    'If recordset is empty, exit
    Do While Not rst.EOF
    distro = distro & ";" & rst.Fields("[Level 1Approver Email]")

    rst.MoveNext
    Loop
    With oOMail_001
    'now use the variable disto with all the email names in the to field of outlook
    '.CC =
    .BCC = distro
    .Subject = "Wireless Telecommunication Approval - Reminder 2"
    .Body = "Body"
    .display
    .BodyFormat = 1
    End With
    rst.Close
    Set rst = Nothing
    Set db = Nothing
    End Sub

    I want to insert an update command either by using DoCmd.RunSQL, but I am not sure where to put it in the above code so that each record that is emailed gets updated.

  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,530
    At the simplest, right before this line:

    rst.MoveNext

    Downside being that that the user could not actually send the email. You may be able to use the Edit method of the recordset instead of SQL.
    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. How to update subform records using loop
    By tahirsatti in forum Forms
    Replies: 15
    Last Post: 05-13-2013, 01:22 AM
  2. Loop using a command button
    By dref in forum Forms
    Replies: 5
    Last Post: 09-09-2012, 07:02 PM
  3. Coded Loop v SQL Update Query Performance
    By bginhb in forum Programming
    Replies: 5
    Last Post: 01-21-2012, 03:02 PM
  4. Bulk Email / Loop through recordset
    By smikkelsen in forum Forms
    Replies: 4
    Last Post: 07-12-2010, 06:59 PM
  5. update table in loop based on IF statement
    By LALouw in forum Access
    Replies: 0
    Last Post: 07-26-2009, 08:46 PM

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