Results 1 to 10 of 10
  1. #1
    DennisAS is offline Novice
    Windows 7 64bit Access 2013 32bit
    Join Date
    May 2017
    Posts
    5

    Removing Duplicates from Query Results or Mailing Label Report

    I am trying to adjust a query or report that will get me the addresses of all the monthly non-contract vendors for the our Flea Market for the last eight months for printing mailing labels. I have the query created but I need a way to remove duplicates since many of the vendors have sold multiple months. I've included the unique VendorID in the query in the hopes that it can be used either in the query itself or the mailing labels Report to eliminate all but one of the duplicate entries. I don't want to delete anything, just not have them show in the query results or on the mailing labels.

    I've attached a screenshot of the query design and the current output.

    Here is the SQL generated by Microsoft Access:



    SELECT DISTINCTROW Vendors.[First Name], Vendors.[Last Name], Vendors.[Street Address], Vendors.City, Vendors.State, Vendors.Zipcode, Ticket.Class, Ticket.[Market Date], Vendors.VendorID
    FROM Vendors INNER JOIN Ticket ON Vendors.VendorID = Ticket.[Vendor ID]
    GROUP BY Vendors.[First Name], Vendors.[Last Name], Vendors.[Street Address], Vendors.City, Vendors.State, Vendors.Zipcode, Ticket.Class, Ticket.[Market Date], Vendors.VendorID
    HAVING (((Ticket.Class)<>"Contractor") AND ((Ticket.[Market Date])=#11/5/2016#)) OR (((Ticket.Class)<>"Contractor") AND ((Ticket.[Market Date])=#12/3/2016#)) OR (((Ticket.Class)<>"Contractor") AND ((Ticket.[Market Date])=#1/7/2017#)) OR (((Ticket.Class)<>"Contractor") AND ((Ticket.[Market Date])=#2/4/2017#)) OR (((Ticket.Class)<>"Contractor") AND ((Ticket.[Market Date])=#3/4/2017#)) OR (((Ticket.Class)<>"Contractor") AND ((Ticket.[Market Date])=#4/1/2017#)) OR (((Ticket.Class)<>"Contractor") AND ((Ticket.[Market Date])=#5/6/2017#)) OR (((Ticket.Class)<>"Contractor") AND ((Ticket.[Market Date])=#6/3/2017#))
    ORDER BY Vendors.[Last Name];

    I've tried changing DISTINCTROW to DISTINCT in the SQL as suggested by someone but it did not help.
    I've also tried using the Property Sheet to set Unique Values to Yes and to set Unique Records to Yes but neither helped.

    Click image for larger version. 

Name:	QueryDesign.jpg 
Views:	6 
Size:	159.5 KB 
ID:	28853 Click image for larger version. 

Name:	Output.jpg 
Views:	6 
Size:	168.7 KB 
ID:	28854


  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,521
    Change Group By to Where on the fields with criteria and see what that gives you.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    DennisAS is offline Novice
    Windows 7 64bit Access 2013 32bit
    Join Date
    May 2017
    Posts
    5
    How would I use Where?
    I tried setting it to Where and nothing happened. I think it requires some parameters.

  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,521
    Huh? What does it look like in design view now? Or can you attach the db here?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    DennisAS is offline Novice
    Windows 7 64bit Access 2013 32bit
    Join Date
    May 2017
    Posts
    5
    I posted screenshots of the Design View and part of the output.

  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,521
    Yes, before the changes I recommended. I'm curious what it looks like after implementing those. It should have changed the output dramatically.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    DennisAS is offline Novice
    Windows 7 64bit Access 2013 32bit
    Join Date
    May 2017
    Posts
    5
    I was able to get the answer from the Microsoft Community.
    https://answers.microsoft.com/en-us/...5-5536ab912b99


    From Ken Sheridan:
    The problem is that you are returning the Market Date column in the query's result table, so the rows are not distinct. If you uncheck the 'Show' checkbox for that column in query design view, and use the SELECT DISTINCT predicate this should return one instance of each addressee. Do the same for the Class column. You can then remove the unnecessary grouping from the query.

    Here is a screen shot of the revised query design.
    Click image for larger version. 

Name:	QueryDesignRevised.jpg 
Views:	6 
Size:	141.5 KB 
ID:	28873

  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,521
    You would have gotten the same result by changing Group By to Where, I suspect. In any case, glad you got a solution and welcome to the site by the way!
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  9. #9
    DennisAS is offline Novice
    Windows 7 64bit Access 2013 32bit
    Join Date
    May 2017
    Posts
    5
    Thanks for the welcome.

  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,521
    By the way, if you're near the cities in your data, I'm just over the hill.
    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. Trouble creating mailing label
    By klynn47 in forum Reports
    Replies: 2
    Last Post: 04-20-2016, 10:46 PM
  2. Macro to print a mailing label
    By AntnyBrusk in forum Macros
    Replies: 3
    Last Post: 06-23-2015, 10:07 AM
  3. Replies: 6
    Last Post: 03-29-2013, 11:05 AM
  4. generating mailing label reports
    By Glider_man in forum Reports
    Replies: 7
    Last Post: 04-26-2011, 10:03 AM
  5. access mailing label message
    By fwit in forum Access
    Replies: 1
    Last Post: 07-14-2010, 01:36 PM

Tags for this Thread

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