Results 1 to 15 of 15
  1. #1
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496

    Several locations of a company with same email skip

    I require code that will let me skip emailing a record if it has a matching email of another record - I don't want to be sending the same letter twice to the same email as some of our customers have more than 12 locations that all have the same email on record.



    I thought about the database building and attaching an array that if the email didn't match anything in the array then email - so every record would place it's email in the array and a function would search the array to see if any of them matched.

    Would this be practical and can it be done?

  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
    It might help to see your code, but typically I'd expect to be looping a query of email addresses. That query is where I'd eliminate duplicates, either with DISTINCT or GROUP BY.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by pbaldy View Post
    It might help to see your code, but typically I'd expect to be looping a query of email addresses. That query is where I'd eliminate duplicates, either with DISTINCT or GROUP BY.
    If I can remove duplicates using "DISTINCTROW" like you say and I am assuming it still lets you see one in the query in order for you to email it - that way all emails are delivered only once. Am I right?

  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
    Will, I mentioned DISTINCT, not DISTINCTROW; they aren't the same. In any case, the principle is to create a query that returns the values as you want/need and either use the query or the SQL in a recordset.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by pbaldy View Post
    Will, I mentioned DISTINCT, not DISTINCTROW; they aren't the same. In any case, the principle is to create a query that returns the values as you want/need and either use the query or the SQL in a recordset.
    whoops yeah sorry I picked the wrong one - distinct.

    thanks

  6. #6
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by pbaldy View Post
    Will, I mentioned DISTINCT, not DISTINCTROW; they aren't the same. In any case, the principle is to create a query that returns the values as you want/need and either use the query or the SQL in a recordset.
    Can you write in SQL that you only want to see the one single field as distinct and show the others?

  7. #7
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    DISTINCT won't give me the ID of the school - if I add ID field then I don't get distinct on the email...

  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
    Since the email could be multiple schools, which school's would you want? Sounds like you want a totals query, but you haven't really given much detail.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by pbaldy View Post
    Since the email could be multiple schools, which school's would you want? Sounds like you want a totals query, but you haven't really given much detail.
    My sql prints out as
    Code:
    SELECT tblSchools.NewSchoolsID, tblSchools.SchoolName, tblSchools.AreaID, tblSchools.SchoolEmail, tblSchools.[1ContactName], tblSchools.[1ContactSurname], tblSchools.Removed 
    FROM tblSchools 
    WHERE tblSchools.AreaID=112 AND tblSchools.Removed Is Null;

    now some of these records show the same email - I'd like to define just one (I don't care which) however if I use distinct I won't be able to get fields like newschoolsid - lest I get all the rows.

    doing

    SELECT DISTINCT SchoolEmail
    FROM tblSchools;

    gives me distinct emails but nothing else

    that's why I thought an array would work best, it would go through these records, putting in an email and then looping through the array to check if it is already added (and if not skip or rs.movenext since I am going through a recordset).

  10. #10
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    I guess if I could pass in a public variable to a function and the field (rs!schoolemail) then I could have a bool function

    if bAreadySent(varArray(),rs!schoolemail) = true then
    rs.movenext
    end if

  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
    Since you don't care which, how about:

    SELECT Max(NewSchoolsID) As MySchoolID, Max(SchoolName) As MySchoolName, Max(AreaID) As MyAreaID, SchoolEmail,
    Max([1ContactName]) As MyContactName, Max([1ContactSurname]) As YouKnowTheDrill
    FROM tblSchools
    WHERE tblSchools.AreaID=112 AND tblSchools.Removed Is Null
    GROUP BY SchoolEmail
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  12. #12
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by pbaldy View Post
    Since you don't care which, how about:

    SELECT Max(NewSchoolsID) As MySchoolID, Max(SchoolName) As MySchoolName, Max(AreaID) As MyAreaID, SchoolEmail,
    Max([1ContactName]) As MyContactName, Max([1ContactSurname]) As YouKnowTheDrill
    FROM tblSchools
    WHERE tblSchools.AreaID=112 AND tblSchools.Removed Is Null
    GROUP BY SchoolEmail
    hey that works! but how?

  13. #13
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    It gets the max value of the other fields for each email address. Only works if you don't really care about the other fields, just need a value.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  14. #14
    Ruegen's Avatar
    Ruegen is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Jul 2013
    Location
    Australia
    Posts
    1,496
    Quote Originally Posted by pbaldy View Post
    It gets the max value of the other fields for each email address. Only works if you don't really care about the other fields, just need a value.
    Yes that works well - it's a batch mail out so as long as the email gets out to the email available it doesn't matter which school. If it needed to be personal I wouldn't have used this method.

    Thank you so much

  15. #15
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Happy to help!
    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. For statement - skip value
    By Ruegen in forum Programming
    Replies: 8
    Last Post: 07-21-2014, 07:26 AM
  2. email to many with attachments and data multi company.
    By trevor40 in forum Code Repository
    Replies: 2
    Last Post: 02-18-2014, 04:44 AM
  3. Replies: 1
    Last Post: 10-31-2012, 01:27 PM
  4. Skip a line
    By Bear in forum Queries
    Replies: 13
    Last Post: 08-19-2011, 03:17 PM
  5. Replies: 0
    Last Post: 01-26-2011, 05:51 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