I do have one more question. Can I incorporate a message box into the last
query (the one that unchecks the field [Active] if the last 2 of 3 are
unacceptable)? I would like the user to be made aware of the fact that this
item is no longer active.
Thanks in advance!
:
Glad to hear you got it working
Cheers,
Alex.
:
I'm so excited I can barely speak! You are a genius. Thank you soooo much
for alll your help. I got it and it works great and you have no idea how
much stress this takes off of me!
Thank you sooooo much!
:
Is it possible (I suspect it is) that one company can be linked to more than
one PT ID?
The query as written returns records for [company], [PT Date] and
[Accept/Not Accept] if the [PT ID] for those records is in the top 3 *for
that [PT ID]* by date in [test2].
If [PT ID] does not relate 1:1 with [company] (which it looks like it
doesn't) then you could return any number of companies, depending on how many
[PT ID]s each company has.
Something like:
SELECT [company], [PT Date], [Accept/Not Accept]
FROM test2
WHERE [PT ID] IN
(SELECT TOP 3 [PT ID] FROM [test2] AS D
WHERE D.[company] = [test2].[company]
ORDER BY D.[PT Date] DESC, D.[PT ID] DESC)
ORDER BY [company], [PT Date];
should work, but it may depend on your [test2] query and the structure of
the underlying tables.
The logic here is that the subquery returns the three latest [PT ID]s for a
given company, X, from the current record in the main query. If the record's
[PT ID] is in the top 3 list, that record is returned.
I think this will work; if it doesn't, post back and I'll take another shot.
Cheers,
Alex.
:
Thanks. I'll give that a try...
I did find one other thing that I need help with.
In the first query you gave me that is supposed to pull the top 3, I am
getting all of the records regardless of the date.
I am using:
SELECT [company], [PT Date], [Accept/Not Accept]
FROM test2
WHERE [PT ID] IN (SELECT TOP 3 [PT ID] FROM [test2] AS D WHERE D.[PT
ID] = [test2].[PT ID] ORDER BY D.[PT Date] DESC, D.[PT ID] DESC)
ORDER BY [company], [PT Date];
In the results, I get:
Atlas Thread Gage, Inc. 3/25/2010 Not Acceptable
CMG Sales, Inc. 3/22/2009 Not Acceptable
CMG Sales, Inc. 8/25/2009 Acceptable
CMG Sales, Inc. 12/21/2009 Not Acceptable
CMG Sales, Inc. 3/28/2010 Not Acceptable
Polymer Concentrates, Inc.12/25/2009 Not Acceptable
CMG Sales should be only returning 3 records with the dates 3/28/10,
12/21/09 and 8/25/09.
What am I doing wrong?
P.S. I am using a query as the basis for this query instead of a table
since the Company was in a different table than the rest of the data.
:
Hi again,
After a quick test, it seems Access won't let you omit the value you want to
set the field to. It failed with exactly the same error as you report.
So, you'll need:
UPDATE [Cust Site Item Junction tbl]
SET [active] = 0
WHERE [Cust Site Item Junction tbl].[cust_num] in
(SELECT qdfNGClients.[cust_num]
FROM qdfNGClients);
This will set the [active] field to FALSE, use SET [active] = -1 to set it
to true.
Again, this assumes that it's a Yes/No field; if not, SET [active] = <some
appropriate value>.
Cheers,
Alex.
:
Thank you so much for your help so far!
I took some time to dig in and figured out how to get the rest to work, and
it seems to be working so far. The only problem I am having now is the final
Update qry. I have the following:
UPDATE [Cust Site Item Junction tbl]
SET [active]
WHERE [Cust Site Item Junction tbl].[cust_num] in
(SELECT qdfNGClients.[cust_num]
FROM qdfNGClients);
I wasn't sure if I was missing something or what I did wrong...when I try to
run it, I get the message Syntax error in Update Statement. When I click on
Ok, it highlights the word Where. I looked up the error but all I found was
that it said I might be missing a part of the statement or that it might be
misspelled.
Any ideas?
:
You never even mentioned a second table. Yes it could make a difference.
At this point we don't know what queries you have run or what they look like.
It would help, if you posted the table structure (at least of the fields
involved) and the query or queries you have tried. And a short description of
the results returned - no records, expected records, unexpected records.
John Spencer
Access MVP 2002-2005, 2007-2010
The Hilltop Institute
University of Maryland Baltimore County
sg wrote:
Question: When I run the query, I get no results back, but I definitely have
data that should come up. I see in my original post that I did not state
that the Client ID is from the Cust tbl and not in the PT tbl. However, the
two tables are related to each other in a many-to-many relationship with the
Item junction tbl. Will that make a difference?
:
Hi,
You can do this with queries.
This is untested air-SQL, so use at your own risk <g>.
First you need the latest three PT records per client:
SELECT [PTClientID], [PT Date], [PT Status]
FROM [PT tbl]
WHERE [PTKeyField] IN
(SELECT TOP 3 [PTKeyField]
FROM [PT tbl] AS D
WHERE D.[PTKeyField] = [PT tbl].[PTKeyField]
ORDER BY D.[PT Date] DESC, D.[PTKeyField] DESC)
ORDER BY [PTClientID], [PT Date]
Save this query (e.g. as qdfTopThree), and then use a totals query to find
any clients with 2 or more 'Unacceptable' statuses:
SELECT [PTClientID], Count([PT Status]) AS StatusCount
FROM qdfTopThree
WHERE [PT Status] = "Unacceptable"
GROUP BY [PTClientID]
HAVING Count([PT Status]) >= 2
Once again, save the query (qdfNGClients) and then - after backing up your
database - use an UPDATE query to set your check field:
UPDATE [scope tbl] INNER JOIN qdfNGClients
ON [scope tbl].[ClientID] = qdfNGClients.[PTClientID]
SET [check fld] = 0
Caveat: Once again, this is untested code; please ensure you have a backup
of your database before doing this!
Also, no guarantee that this is the most effective, most elegant, or
quickest method.
Assumptions:
PT tbl has a Primary Key [PTKeyField] which is NOT the Client ID
You have a Client ID to link PT tbl and Scope tbl.
Your check field is a Yes/No field.
Hope this helps (or at least points you in the right direction),
Alex.
:
I have a table called PT tbl. If a client has a status of Unacceptable (a
field in the table) for two out of the three most recent dates (PT Date
field), I need to find them and run a macro that will uncheck a box in
another table (scope tbl).
I am not sure if I need a macro only or if I need a query to first pull
those who are the top two out of three or where to start here. I did get a
query put together to show the top two, but it was just the top two dates out
of the entire client list, not the top two per client.
Any help out there? Thank you in advance for any one who will help!
.