Results 1 to 11 of 11
  1. #1
    Steven.Allman is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2010
    Posts
    118

    Massive Email Project

    This encompasses every aspect of Access, so I just posted it in the general.

    I have become pretty familiar with the email functions, and have just volunteered myself for a new update.

    We are going to call this a lottery notification.
    Employees are selected at random from a list of all employees. If the employee is a winner, we will email their supervisor. I have generated a make table query that selects my winners. The list is 175 names. There are about 40 supervisors. I want a doSendcmd option to send an email to

    Supervisor 1, and include in the body the list of employees HE is the supervisor for.
    Supervisor 2, and her employees..

    SendObject (SendNoObject,,,,strSup,,strEmailEmp,,"Please be advised that the following employees" & "; " & strEmp & " have won the lottery for this month...."

    Its the actual strings I am having trouble with.
    The newly created table is "employees_selected" with the following fields
    employee_name
    supervisor_name
    Supervisor_email
    employee_number (randomly generated and sorted for the "selection" so doesn't really apply to my string)


    Thoughts? or is this impossible?


    I really want to hit ONE button, and it compile the 30-60 emails at once. I could easily do a single email and BCC all supervisors with the entire list saved as a PDF, that's easy, but I don't need all supervisors knowing who won the lottery.

    Am I insane?

  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
    Not terribly difficult. I'd use 2 recordsets. The first would be the supervisors and their email address. Inside a loop of that, open a recordset on your table using the supervisor from the loop in the criteria. Loop that recordset and build your string of employees, then send an email.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Steven.Allman is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2010
    Posts
    118
    Mind Blown...
    But would this then require me to hit an email button 35-55 times?
    Or would this one code write the separate emails and send them all out?
    I have never done a loop, and wouldn't know where to start on that.

  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
    You can either generate the emails and let the user send each one, or send them automatically with one click. Here's my template code for a recordset loop:

    Code:
      Dim strSQL  As String
      Dim db      As DAO.Database
      Dim rs      As DAO.Recordset
    
      Set db = CurrentDb()
      
      strSQL = "SELECT ..."
      Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
    
      Do While Not rs.EOF
    
        rs.MoveNext
      Loop
    
      rs.Close
      set rs = nothing
      set db = nothing
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Steven.Allman is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2010
    Posts
    118
    Ok, right now you are on a whole new plane of existence.
    Pretending I am a child, break it down.

    Instead of using my query to create a single table with my 4 aforementioned fields,
    I should create a table and sub-table (is that possible?) with Supervisor and any subordinates..
    I cant create a relationship due to the table being deleted and overwritten when I run the lottery again.

    I have attached some sample data from a ghost database that does mimics the process I want.
    Attached Files Attached Files

  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
    No, your first recordset is based on SQL that gets just the unique supervisors and their emails (SELECT DISTINCT...). The second uses the supervisor from the first loop to pull the employees of that supervisor from the same table.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    ssanfu is offline Master of Nothing
    Windows XP Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by Steven.Allman View Post
    <snip> I have generated a make table query that selects my winners. The list is 175 names.<snip>
    IMO, it would be better to create the table once, then delete the old records and append new records.
    Constantly deleting tables and recreating them is a good way to introduce corruption.

    You can still use the query, just change it from a make table to an append query.
    Use code to first execute a delete query, then the append query.

  8. #8
    Steven.Allman is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2010
    Posts
    118
    Quote Originally Posted by ssanfu View Post
    IMO, it would be better to create the table once, then delete the old records and append new records.
    Constantly deleting tables and recreating them is a good way to introduce corruption.

    You can still use the query, just change it from a make table to an append query.
    Use code to first execute a delete query, then the append query.
    That's a good idea there. I could then actually probably figure this out using a different query with relationships going back to original table too. Its the delete table that was making me scratch my head.

  9. #9
    Steven.Allman is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2010
    Posts
    118
    Quote Originally Posted by pbaldy View Post
    You can either generate the emails and let the user send each one, or send them automatically with one click. Here's my template code for a recordset loop:

    Code:
      Dim strSQL  As String
      Dim db      As DAO.Database
      Dim rs      As DAO.Recordset
    
      Set db = CurrentDb()
      
      strSQL = "SELECT ..."
      Set rs = db.OpenRecordset(strSQL, dbOpenDynaset)
    
      Do While Not rs.EOF
    
        rs.MoveNext
      Loop
    
      rs.Close
      set rs = nothing
      set db = nothing

    Ok, so here is my code right now


    Private Sub Command31_Click()
    Dim rstmasterList As DAO.Recordset
    Dim strTo As String
    Set rstmasterList = CurrentDb().OpenRecordset("SELECT * FROM master WHERE [Name]='" & [Selected_personnel]![Name] & "'", dbOpenDynaset)
    strTo = ""
    If Not IsNull(rstmasterList("SUPV Email Address")) Then
    strTo = strTo + rstmasterList("SUPV Email Address")
    End If
    DoCmd.SendObject acSendNoObject, , , rstRecordset, strTo, Bcc, Subject, MessageText, , 0
    End Sub

    Of course, now figuring out how to put that loop in there. Obviously this isn't working as is, because I have no reference for the [NAME] field, I am sure this is where you are telling me to add the loop feature, but I am seriously lost on that one. No idea how to make that work.

  10. #10
    Steven.Allman is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Feb 2010
    Posts
    118
    And I think I am really doing that wrong... It may write one email to the supervisor for each employee, meaning one supervisor may get 3 emails, but I am ok with that for now.

  11. #11
    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 can send a single email to each supervisor listing all their employees. In generic terms:

    Code:
    Start loop on list of supervisors
      open recordset on table using current supervisor as criteria
      start loop of employees of that supervisor
        'build a string of those employees   
        strEmployees = strEmployees & rs!Employee
      End inner loop
    
      Send email using above string
    End outer loop
    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. Massive data loss
    By Homegrownandy in forum Access
    Replies: 5
    Last Post: 08-26-2015, 01:08 AM
  2. Access Massive Data Lookup
    By sarahd09 in forum Access
    Replies: 2
    Last Post: 09-16-2014, 05:10 PM
  3. having to deal with massive query's
    By quandore in forum Access
    Replies: 1
    Last Post: 01-11-2012, 08:34 AM
  4. Massive check-list database
    By JFo in forum Access
    Replies: 103
    Last Post: 09-19-2011, 07:06 PM
  5. Massive help from ground up
    By Steven.Allman in forum Access
    Replies: 14
    Last Post: 02-20-2010, 05:48 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