Solved

Too many results for query

Posted on 2011-09-09
7
224 Views
Last Modified: 2012-06-21
Morning,

I have the following error and could not find any resources to help me here or in internet

I am running a query which will sort a column of combinations and related fields based on user entered values. Since I did not know any other ways, I went in to query design view and in the criteria (of the combination column) put in the following

(GetO([Forms]![Point2Point]![ocitytxt] & [Forms]![Point2Point]![oprovcombo])) & (GetO([Forms]![Point2Point]![dcitytxt] & [Forms]![Point2Point]![dprovcombo]))

Open in new window


GetO is a function and rest are user entered fields. I've done a self test on the fields and they are populating fine. The problem is, when I run the query, instead of populating nearly 17 records (based on combination), its populating 94,000 rows and related data

The combination is same but its duplicating the data on the output of query!

Anyone know any common source of this? Any help is much appreciated as this is blocking me from proceeding :/

Thanks!

0
Comment
Question by:Shanan212
7 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 36510555
did you use Group By in your query ?

0
 
LVL 77

Expert Comment

by:peter57r
ID: 36510559
Please post the sql view of your query
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 36510607
It would also be useful to know either what the Get0() function code looks like, or what the function returns for a couple of values.
0
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
LVL 13

Author Comment

by:Shanan212
ID: 36510647
SQL of query

SELECT INTER.TCOMBI, INTER.LTL, INTER.[500], INTER.[1M], INTER.[2M], INTER.[5M], INTER.[10M], INTER.[20M] INTO BTER
FROM OUT, INTER
WHERE (((INTER.TCOMBI)=(GetO([Forms]![Point2Point]![ocitytxt] & [Forms]![Point2Point]![oprovcombo])) & (GetO([Forms]![Point2Point]![dcitytxt] & [Forms]![Point2Point]![dprovcombo]))));

Open in new window


Only 1 column is filtered using function above

GetO function is in Module1 - Returns a combination based on 4 user entered values. Again, this part is working as the query is actually sorting but somehow bringing in way too many duplicates instead of 17.

Function GetO(origin As String) As String

        Dim rst As DAO.Recordset
        Dim strSQL As String
        Dim varResult As String
        
        strSQL = "Select OUT.TCOMBI " & "FROM OUT " & "WHERE OUT.OUTCOMBI = '" & origin & "' " '& "ORDER BY tblAll.City;"
        Set rst = CurrentDb.OpenRecordset(strSQL)
        
        If Not (rst.EOF And rst.BOF) Then
            GetO = DLookup("TCOMBI", "OUT")
        End If
        
        Set rst = Nothing
        
End Function

Open in new window

0
 
LVL 22

Accepted Solution

by:
Thomasian earned 500 total points
ID: 36510730
Including OUT table on the query causes a cross join between the 2 tables, thus it is returning duplicates. Exclude it from the query since the record is retrieved inside the function
SELECT INTER.TCOMBI, INTER.LTL, INTER.[500], INTER.[1M], INTER.[2M], INTER.[5M], INTER.[10M], INTER.[20M] INTO BTER
FROM INTER
WHERE (((INTER.TCOMBI)=(GetO([Forms]![Point2Point]![ocitytxt] & [Forms]![Point2Point]![oprovcombo])) & (GetO([Forms]![Point2Point]![dcitytxt] & [Forms]![Point2Point]![dprovcombo]))));

Open in new window

0
 
LVL 13

Author Comment

by:Shanan212
ID: 36510771
Wow! Its a matter of having that table opened in the design view eh!
I removed that table and it worked like a charm :)
Thanks a ton!
0
 
LVL 13

Author Closing Comment

by:Shanan212
ID: 36510776
Thank you for an eye-opening lesson!
0

Featured Post

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question