Results 1 to 8 of 8
  1. #1
    TazoTazmaniac is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Nov 2014
    Posts
    41

    Query pulls duplicates

    Hi everyone,



    Having a big problem to which I can't find the solution. I'm creating a database that involves stock, customers, deliveries and collections and I want to make a delivery report. I've spent a lot of time on making the main database and have only started on one report so far so I may be tackling it completely wrong from the beginning (please tell me if so!)

    So, the report that I want to make includes a lot of fields, so I have based it on a large query containing 7 tables (the SQL for which is below). It looks very cumbersome, so not sure if this is the way to go, but have no idea how else to do it otherwise. Now, the problem is that the query comes up with duplicates of the same delivery and I'm not sure why. In fact, it has duplicated the same delivery 96 times. I suspect it is something to do with an incorrect join, but have no idea how to find out which, or even how to correct it! If more information is needed, I'll gladly give it.

    Please, please, please can someone point me in the right direction - it would be much appreciated! Thank you in advance for your time.

    Code:
    SELECT tblDelivery.DeliveryID, tblDelivery.DeliveryDate, tblDelivery.[AM/PM], tblDelivery.Notes, tblDelivery.PropertyType, tblDelivery.Bedrooms, tblDelivery.Floor, tblDelivery.Invoice, tblDelivery.[Owned/Rented], tblDelivery.NewOccupancy, tblAllocation.NumberRequested, tblClientDonorContact.ContactFirstName, tblClientDonorContact.ContactLastName, tblClientDonorContact.ContactNumber, tblClientDonorContact.AlternativeContactNumber, tblClientDonorContact.Referral, tblClientDonorContact.ReferralContact, tblClientDonorContact.ReferralTelNo, tblClientDonorContact.ReferralInfo, tblAddresses.Address1, tblAddresses.Address2, tblAddresses.Area, tblAddresses.Postcode, tblDelivery.ContactID, tblAllocation.NumberAllocated, tblDelivery.AddressID, tblStockDescription.Description, tblOccupancyEthnicity.Occupancy, tblDelivery.TakenBy, tblDelivery.LiftAvailable, tblAllocation.RequestNotes, tblAllocation.ItemID
    
    FROM (((tblClientDonorContact 
    
    INNER JOIN tblDelivery ON tblClientDonorContact.ContactID = tblDelivery.ContactID) 
    
    INNER JOIN tblOccupancyEthnicity ON tblClientDonorContact.ContactID = tblOccupancyEthnicity.ContactID) 
    
    LEFT JOIN tblAddresses ON tblClientDonorContact.ContactID = tblAddresses.ContactID) 
    
    INNER JOIN ((tblStock INNER JOIN tblAllocation ON tblStock.ItemID = tblAllocation.ItemID) 
    
    INNER JOIN tblStockDescription ON (tblStock.ItemID = tblStockDescription.ItemID) AND (tblAllocation.ItemID = tblStockDescription.ItemID)) ON tblDelivery.DeliveryID = tblAllocation.DeliveryID
    
    WHERE (((tblDelivery.DeliveryDate)=Tomorrow(Date())));

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    "Duplicates" probably occur because I am guessing the query includes several tables that are the 'many' side of relationships with another table. This would be the expected output in such a query. You should probably consider report/subreport(s) arrangement.
    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.

  3. #3
    TazoTazmaniac is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Nov 2014
    Posts
    41
    Now you've said it, that seems like an obvious thing to do. D'oh! Thank you, I shall give that a try.

  4. #4
    TazoTazmaniac is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Nov 2014
    Posts
    41
    Thank you for the earlier help. I am now having a similar problem which I am unable to solve again.

    I'm now getting just one set of duplicate results. Earlier, I viewed the query in datasheet mode and could see that that was where the problems lay as the duplicates were there. I have now made two seperate queries for a report and subreport and they both seem to work fine with no duplicates. However, once I put them on the report together, I get a duplicate in the detail section (most of the fields I put into the header as I only need one record per report, but stock items I put into the detail section as it could be several different items).

    Not sure where to go here. Any suggestions? I can post extra information needed tomorrow if necessary, but I don't currently know what information you might need!

    Thank you again for your help.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    No idea why that happens. If you want to provide db for analysis, follow instructions at bottom of my post.
    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.

  6. #6
    TazoTazmaniac is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Nov 2014
    Posts
    41
    I've attached my database containing fake information. The report I'm talking about is 'rptTomorrowsDeliveries2' with sub 'rptTomorrowsDeliveriesSub' and the main report is based on the query 'qryTomorrowsDelAddressAndStockReport', and I think in the end I based the sub report on tblClientDonorContact' and allowed the wizard to create the query itself. I don't think it made a difference either way I did it.

    The problem on the report is that the person being delivered to only has one dressing table allocated to them, but it shows up twice on the report.

    Let me know if you have any ideas. Thanks again.

    SC Rebuilt Stock Database v 6.4.1.6_forum.zip

  7. #7
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    I open rptTomorrowDeliveries2 and it shows only one dressing table record.


    qryTomorrowsDeliveries has tblStockDescription linked to be tblStock and tblAllocation. Remove one of the links. Tables normally should not be linked on autonumber fields. If these two tables have a 1-to-1 relationship, why not combine to one table?
    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.

  8. #8
    TazoTazmaniac is offline Advanced Beginner
    Windows 7 64bit Access 2013
    Join Date
    Nov 2014
    Posts
    41
    That's odd. Definitely was doing that the last couple of days! Must've done something to sort it accidently or something. Thank you for your help anyway, it's been appreciated!

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 2
    Last Post: 12-04-2013, 03:58 PM
  2. Replies: 10
    Last Post: 08-21-2012, 07:16 AM
  3. Form pulls totals from query
    By seth.murphine in forum Forms
    Replies: 3
    Last Post: 04-17-2012, 08:23 AM
  4. Form pulls info from 2 tables.
    By Jonpro03 in forum Forms
    Replies: 6
    Last Post: 07-20-2011, 11:33 AM
  5. Replies: 1
    Last Post: 02-13-2010, 12:44 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