Results 1 to 3 of 3
  1. #1
    talhaparvaiz@yahoo.com is offline Novice
    Windows 7 64bit Access 2013 64bit
    Join Date
    May 2020
    Posts
    29

    deleting multiple records from the table

    Good day,

    Following code sends out multiple emails (variable i, in this example it is set to 10) to multiple BCC address per email (based on the variable x, in this example it is 40 but can change as it is a variable).

    Once an email is sent, I want to delete email addresses from the table before running the loop i again. Something like that


    When i = 1
    Step 1: send email to 40 BCC email address
    Step 2: delete 40 email addresses (the ones sent in step 1) from the table

    When i = 2


    Step 1: send email to 40 new BCC email address
    Step 2: delete 40 email addresses (the ones sent in step 1) from the table


    Please advise





    Code:
    Option Compare Database
    
    Sub Command0_Click()
    
    
    Dim sFileName As String, sEmail As String, BccEmail As String, eBody As String
    Dim rst As DAO.Recordset
    
    
    
    
    Set rst = CurrentDb.OpenRecordset("tbl_Email", dbOpenSnapshot) ' Table Name
    
    
     eBody = "<HTML><BODY>message</BODY></HTML>"
    
    
    
    
    
    
    
    
    On Error Resume Next
    rst.MoveFirst
    
    
    
    
    
    
    
    
    Dim i As Integer
    Dim x As Integer
    
    
    For i = 1 To 10 'sending emails individually
    
    
        sEmail = rst("Email_Address")  'Field Name
        CCEmail = sEmail
        BccEmail = ""
        
        
        
        For x = 1 To 40 'Adding 40 email addreses to BCC
        If Not rst.EOF Then
        BccEmail = BccEmail & ";" & sEmail
        rst.MoveNext
        sEmail = rst("Email_Address")
        End If
        Next x
        
        If BccEmail <> "" Then
        Call vcSendEmail_Outlook_With_Attachment("Seeking BA opportunities", "To@yahoo.com", "", BccEmail, "\\fs2\Desktop\personal\Doc.docx", eBody)
        Call Wait_Time
        End If
    Next i
    
    
    
    
    rst.Close
    Set rst = Nothing
    End Sub

  2. #2
    davegri's Avatar
    davegri is online now Excess Access
    Windows 10 Access 2016
    Join Date
    May 2012
    Location
    Denver
    Posts
    3,405
    Right before Next x
    add
    rst.delete

    This assumes you want to delete the entire record from tbl_email and not just blank out the field leaving the record.

  3. #3
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,898
    You are putting email address records into a temp table? Why not just apply filter to recordset SQL?
    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. Replies: 5
    Last Post: 03-11-2019, 02:35 PM
  2. Replies: 1
    Last Post: 07-27-2018, 10:34 PM
  3. Deleting Multiple Records
    By Eranka in forum Access
    Replies: 3
    Last Post: 06-04-2018, 08:37 AM
  4. Replies: 2
    Last Post: 05-15-2013, 09:03 PM
  5. Deleting multiple records selected in a Listbox
    By ankitmehtta in forum Access
    Replies: 4
    Last Post: 11-08-2011, 01:20 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