My Assistant
![]() ![]() |
|
|
Oct 20 2008, 02:48 PM
Post
#1
|
|
|
UtterAccess Enthusiast Posts: 54 |
I have a problem where I want to use the DISTINCT selection criteria, but only on one field in my query. Here is the query:
CODE SELECT DISTINCT tblCompany.strCompany, tblInvoices.*, tblNotices.*, tblAccount.strAccountNum, tblAccount.strMembership, tblAccount.strAgent FROM tblCompany, tblAccount, tblInvoices, tblNotices WHERE tblAccount.numCompanyID=tblCompany.anmCompanyID AND tblInvoices.numCompanyID=tblAccount.numCompanyID AND tblAccount.numCompanyID=tblNotices.numCompanyID ORDER BY tblCompany.strCompany This query is being used as the Recordsource for a form which has a number of subforms attached to it. I would like to use the field tblCompany.strCompany as the distinct selection criteria. I have tried many things in order to achieve my goal: 1) Take out tblAccount.strAccountNum of the query (but when I do, and run the query, access pops up with a window when I run a procedure on the form the query is being executed with asking for an "account number" as if it were a variable. I can get the results I want, but not without the popup window) 2) Use a subquery to select a distinct company (this did not work either) 3) Place parenthesis around tblCompany.strCompany (this was unsuccessful) 4) Use a GROUP BY statement (I had to restructure the query to do this, and it would not allow me to use the query without an error occurring) This is all I could think of to solve my problem. I appreaciate any hints on how to solve my problem. Thanks. - Joe |
|
|
|
Oct 20 2008, 03:21 PM
Post
#2
|
|
|
New Member Posts: 18 |
You could try something like this:
SELECT distinctCompanies.strCompany, tblInvoices.*, tblNotices.*, tblAccount.strAccountNum, tblAccount.strMembership, tblAccount.strAgent FROM (SELECT DISTINCT anmCompanyID, strCompany FROM tblCompany) as distinctCompanies, tblAccount, tblInvoices, tblNotices WHERE tblAccount.numCompanyID=distinctCompanies.anmCompanyID AND tblInvoices.numCompanyID=tblAccount.numCompanyID AND tblAccount.numCompanyID=tblNotices.numCompanyID ORDER BY distinctCompanies.strCompany That was just air coded...but it sould(?) work! Give it a shot (IMG:http://www.utteraccess.com/forum/style_emoticons/default/sad.gif) |
|
|
|
Oct 23 2008, 02:21 PM
Post
#3
|
|
|
UtterAccess Enthusiast Posts: 54 |
I found the solution to my problem. I am still able to use DISTINCT, but had to change the Recordsource of each of the subforms.
Thanks for the help. - Joe |
|
|
|
![]() ![]() |
|
Go to Top · Lo-Fi Version | Time is now: 25th May 2013 - 07:49 AM |