Page 1 of 2 12 LastLast
Results 1 to 15 of 27
  1. #1
    d9pierce1 is offline Expert
    Windows 10 Access 2019
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776

    Report Query with select distinct question

    HI all,
    I am sorry but I cant upload due to 2 mb restrictions and I cant get my db any less then 2.49

    I have a report query that I need to some how get to show me disticnt business names and I have tried everything.

    What happens is if a business has more then one Industry or Role, or Function it gives a record for each one and I only want to show the business name once wither it has one or more Industry, role, or function!



    Here is the origional query in sql
    Code:
    SELECT tblBusiness.BusinessID, tblBusiness.BusinessName, qryEntityNotPrimary.BusinessEntityID, qryEntityNotPrimary.CboDataValue AS EntityType, qryEntityNotPrimary.SystemValue, qryAddressPrimary.CboDataValue AS AddressType, qryAddressPrimary.Address, qryAddressPrimary.AddressCont, qryAddressPrimary.City, qryAddressPrimary.State, qryAddressPrimary.ZipCode, qryAddressPrimary.County, qryPhonePrimary.CboDataValue AS PhoneType, qryPhonePrimary.Description, qryPhonePrimary.PhoneNumber, IIf(IsNull([DBA]),[BusinessName],[BusinessName] & ", DBA: " & [DBA]) AS FullBusinessName, Trim([Address] & " " & [AddressCont]) AS FullAddress, qryEntityNotPrimary.Reference, qryEntityNotPrimary.DBA, tblBusiness2BusinessPrimaryFunctionNew.BusinessPrimaryFunctionID, tblBusiness2BusinessPrimaryFunctionNew.BusinessPrimaryRoleID, tblBusiness2BusinessPrimaryFunctionNew.BusinessPrimaryIndustryID
    FROM (((tblBusiness INNER JOIN qryEntityNotPrimary ON tblBusiness.BusinessID = qryEntityNotPrimary.BusinessID) LEFT JOIN qryPhonePrimary ON qryEntityNotPrimary.BusinessEntityID = qryPhonePrimary.BusinessEntityID) LEFT JOIN qryAddressPrimary ON qryEntityNotPrimary.BusinessEntityID = qryAddressPrimary.BusinessEntityID) INNER JOIN tblBusiness2BusinessPrimaryFunctionNew ON tblBusiness.BusinessID = tblBusiness2BusinessPrimaryFunctionNew.BusinessID;
    And I tried this below but got syntax error in the FROM?
    Code:
    SELECT DISTINCT tblBusiness.BusinessID, tblBusiness.BusinessName FROM (SELECT DISTINCT tblBusiness.BusinessID, tblBusiness.BusinessName, qryEntityNotPrimary.BusinessEntityID, qryEntityNotPrimary.CboDataValue AS EntityType, qryEntityNotPrimary.SystemValue, qryAddressPrimary.CboDataValue AS AddressType, qryAddressPrimary.Address, qryAddressPrimary.AddressCont, qryAddressPrimary.City, qryAddressPrimary.State, qryAddressPrimary.ZipCode, qryAddressPrimary.County, qryPhonePrimary.CboDataValue AS PhoneType, qryPhonePrimary.Description, qryPhonePrimary.PhoneNumber, IIf(IsNull([DBA]),[BusinessName],[BusinessName] & ", DBA: " & [DBA]) AS FullBusinessName, Trim([Address] & " " & [AddressCont]) AS FullAddress, qryEntityNotPrimary.Reference, qryEntityNotPrimary.DBA, tblBusiness2BusinessPrimaryFunctionNew.BusinessPrimaryFunctionID, tblBusiness2BusinessPrimaryFunctionNew.BusinessPrimaryRoleID, tblBusiness2BusinessPrimaryFunctionNew.BusinessPrimaryIndustryID)
    FROM (((tblBusiness INNER JOIN qryEntityNotPrimary ON tblBusiness.BusinessID = qryEntityNotPrimary.BusinessID) LEFT JOIN qryPhonePrimary ON qryEntityNotPrimary.BusinessEntityID = qryPhonePrimary.BusinessEntityID) LEFT JOIN qryAddressPrimary ON qryEntityNotPrimary.BusinessEntityID = qryAddressPrimary.BusinessEntityID) INNER JOIN tblBusiness2BusinessPrimaryFunctionNew ON tblBusiness.BusinessID = tblBusiness2BusinessPrimaryFunctionNew.BusinessID;
    Thank you for any assistance on that
    Dave

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Ever heard of a zip file?
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    madpiet is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    154
    Quote Originally Posted by d9pierce1 View Post
    HI all,
    I am sorry but I cant upload due to 2 mb restrictions and I cant get my db any less then 2.49

    I have a report query that I need to some how get to show me disticnt business names and I have tried everything.

    What happens is if a business has more then one Industry or Role, or Function it gives a record for each one and I only want to show the business name once wither it has one or more Industry, role, or function!
    I don't think there's enough information here to answer your question. If you want to force the business name to show up only once in your report, create a report grouping on the Business Name.

    In theory, you could base the report on the entire query (where the child records would cause duplicates to appear in the Business Name column), and put the Business Name column in the header and group it, and it would only show up once.

    As for the file being too big, did you try zipping it?

  4. #4
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    Zip limit is 2mb, non-zip is 500kb

    Have you run Compact & Repair? Make a copy and delete some data or objects?

    Have you used report Sorting & Grouping design features?

    Textbox has HideDuplicates property.
    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.

  5. #5
    d9pierce1 is offline Expert
    Windows 10 Access 2019
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Hi all,
    I took everything out of it I could, it is 10.4mb unzipped and 2.49mb zipped. I will try to take someother things out but ran into issues with this earlier today and got errors galore on opening it.
    But I will try some more.

  6. #6
    June7's Avatar
    June7 is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I doubt viewing your db will change advice.

    Options:

    1. report Grouping and/or textbox Hide Duplicates

    2. report/subreport 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.

  7. #7
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    I took everything out of it I could, it is 10.4mb unzipped
    I imagine you use embedded images on forms, command buttons and such?
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    d9pierce1 is offline Expert
    Windows 10 Access 2019
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Hi Micron,
    No images embedded in forms. Its just a lot
    But thanks for that

  9. #9
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    OK, that would have been my suspicion because these images are usually hidden in system tables. When someone says they can't get the db down in size even though they've compacted it and removed a lot of forms/reports/queries/macros/tables, it's usually because the images are still there.

    There are probably those here who would download your file from a file share and take a look.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  10. #10
    madpiet is offline Competent Performer
    Windows 10 Office 365
    Join Date
    Feb 2023
    Posts
    154
    What's a lot?
    One way of doing it is to create a new blank database and maybe create a few linked tables to the original that you want to get data from and select a subset of the entire table. Do the same for the child tables required for the report. Then import the report.
    yeah, it's some work, but how badly do you need an answer?

  11. #11
    Join Date
    Apr 2017
    Posts
    1,681
    Based on your query, unless you have some serious problems with your DB structure, there is no need for DISTINCT clause in report's source query. Probably the query you need will be like:
    Code:
    SELECT
        bs.BusinessID, 
        bs.BusinessName,
        qenp.BusinessEntityID,
        qenp.CboDataValue AS EntityType,
        qenp.SystemValue,
        qap.CboDataValue AS AddressType,
        ...
    FROM
        (((tblBusiness bs
            INNER JOIN tblBusiness2BusinessPrimaryFunctionNew bspf2 ON bs.BusinessID = bspf2.BusinessID)
            INNER JOIN qryEntityNotPrimary qenp ON bs.BusinessID = qenp.BusinessID)
                LEFT JOIN qryPhonePrimary qpp ON qenp.BusinessEntityID = qpp.BusinessEntityID)
                LEFT JOIN qryAddressPrimary qap ON qenp.BusinessEntityID = qap.BusinessEntityID
    WHERE [Some condition to ensure only primary businesses from tblBusiness are selected]
    You group your report on BusinessID, and you will have BusinessName (and BusinessID in case you want to display this too) in header of report group displayed (i.e. into header you put control(s) for [bs.BusinessID and] bs.BusinessName. The rest of info is displayed row-wise in detail part of group (i.e. into detail part you enter controls for [qenp.BusinessEntityID,] qenp.CboDataValue, qenp.SystemValue, ... etc.). And into footer part of group, you can put some statistics about this business, like the count of sub-businesses it has, or the total of yearly income when you have it for sub-businesses, etc.
    .

  12. #12
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Would be easier to create a new empty DB and import just what you need to show the issue. Test it first and if that can still show the error, then upload that.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  13. #13
    d9pierce1 is offline Expert
    Windows 10 Access 2019
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Blank Profile Business - Copy.zip

    Hi all,
    I sized it down so could zip up and attached.
    Will open to frmBusiness
    Hit report tab, I only left one report in it and removed most all records
    So, when I select the report, it opens showing 3 of the same business (which I only left one business in it)
    If I select from report filter, Construction from the Industry, then it still shows up 3 of the same business, If I then select General Contractor from the Primary Role list,
    and run report, then it will show 2 of the same business. If I select Then select Construction Management from the Functions as list, then it will only show 1 business.
    This does what it is being told but what I want to tell it is no matter what is selected, if its the same business, then only show one business no matter how many Industry, roles, or functions it may have.
    Hope thaat makes sense. I just would like it to show one business on the report, not 2 or 3 or however many insustries, roles, or functions it may have!

    I may need to remove the BusinessPrimaryIndustryID, BusinessPrimaryRoleID, BusinessPrimaryFunctionID and table from that query and on the report, reference those txtboxes on report to the actual lstbox on the report form?
    Code:
    =[Forms]![frmBusiness]![sfrmBusinessContact].[Form]![frmBusinessReport]![LstIndustry.Column(0)]
    =[Forms]![frmBusiness]![sfrmBusinessContact].[Form]![frmBusinessReport]![LstCategory.Column(0)]
    =[Forms]![frmBusiness]![sfrmBusinessContact].[Form]![frmBusinessReport]![LstFunction.Column(0)]
    I tried putting above into the fields on report form but they dont work, most likely I am not referencing the lstbox correctly?
    Any suggestions would be greatly appreciated!

    Thanks
    Dave
    Last edited by d9pierce1; 03-05-2024 at 07:16 AM. Reason: added info

  14. #14
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    open the report query and scan across the fields and you should be able to see why you get more than one record, then the solution should be obvious.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  15. #15
    d9pierce1 is offline Expert
    Windows 10 Access 2019
    Join Date
    Jan 2012
    Location
    Oklahoma
    Posts
    776
    Hi Micron,
    I know why its getting the multi records, what I dont know is how to not show duplucates and still use my report filter?
    Thanks

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 1
    Last Post: 06-23-2020, 03:30 AM
  2. Replies: 6
    Last Post: 05-05-2020, 11:21 PM
  3. Replies: 6
    Last Post: 12-01-2016, 03:40 PM
  4. Delete and/or Select Distinct records query
    By admessing in forum Queries
    Replies: 39
    Last Post: 02-14-2012, 03:50 PM
  5. Replies: 8
    Last Post: 04-21-2011, 05:29 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