Results 1 to 10 of 10
  1. #1
    Ceadmo is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    16

    Query to select cetain items during a specific time period

    I maintain a smalldatabase that keeps tracks of the date and plate numbers of vehicles that are illegallyparked in our parking lot. There areonly three fields in the database: date, plate # and Violation (reason for theticket).
    I want to be able to run asearch that covers a specific time frame (I’m using the BETWEEN command to dothis) and find all plate numbers that appear three or more times during thisperiod along with the violation.


    I have tried using thegreater than symbol but it would not work, the Plate # field is not a numericalfield; it is composed of Apha characters and numbers, therefore a text field.
    I am not experience inusing code and use the wizards to set up my tasks.
    I appreciate any help in preparinga query to do this.

  2. #2
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    FYI Date is a reserved word in Access and should NOT be used.
    Use a Totals query and Count for the Total and >1 for the criteria.

    HTH

  3. #3
    Ceadmo is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    16
    Thanks Dave, for the correction regarding the "Date" field, I will adjust it. Your suggestion gives me totals of the repeats. What I wish is to see are the records of all the instances when a Plate # appears more than three times during the requested period.

  4. #4
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    I would suggest you create a new query and add the old one to it and then set the criteria.

    HTH

  5. #5
    Ceadmo is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    16
    Thanks Dave but how would I add the old query to a new one when both queries have the same fields, would take confuse the query. I may be novice at this but would a single query looking for repeats in a field be easier or is there no way for the program to do this?

  6. #6
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Essentially you create a Find Duplicates Query, save it then add it to a new query and average the NumberOfDups with Criteria of >3 and Total as Avg.
    Otherwise you may have to upload a DEMO copy for analysis!

    HTH

  7. #7
    Ceadmo is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    16
    Plate Number Database.zipPlate Number Database.zip

    Thanks again Dave, but I wasn't looking for totals and averages, I want the output to be a data listing of those Plate number, Date and Violation of all the vehicles that showup in the db more than 3 times during a certain time frame.
    As you suggested I have uploaded a sample db. When the query is run I wish to see only two results from this data Plate Numbers FGB 683 and FHV 284 plus the date and violation for each entry.

  8. #8
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    It has already been downloaded. Good Luck With Your Project!

  9. #9
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    Try:

    SELECT [Plate Numbers].ID, [Plate Numbers].TBLDate, [Plate Numbers].[Plate Number], [Plate Numbers].Vioation, DCount("[Plate Number]","[Plate Numbers]","[Plate Number]='" & [Plate Number] & "'") AS CountViolations
    FROM [Plate Numbers];

    Now apply filter criteria under TblDate and CountViolations fields.

    or
    SELECT * FROM [Plate Numbers] WHERE [Plate Number] IN
    (SELECT [Plate Number]
    FROM [Plate Numbers]
    WHERE TBLDate Between [start] And [end]
    GROUP BY [Plate Number]
    HAVING Count(ID)>=3);

    Advise no spaces in naming convention.

    Note misspelled Violation as Vioation for field name.
    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.

  10. #10
    Ceadmo is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Sep 2014
    Posts
    16
    Thanks for your solution to my problem, it took me a little time to understand the solution, but when I did it worked perfectly. Now to apply it to the big Database. Once again, thanks for your help.

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

Similar Threads

  1. Replies: 11
    Last Post: 07-10-2014, 03:21 PM
  2. Replies: 2
    Last Post: 10-30-2013, 11:40 AM
  3. Replies: 3
    Last Post: 12-01-2012, 12:37 PM
  4. Query for Specific 24 hour time period
    By esh112288 in forum Queries
    Replies: 1
    Last Post: 10-23-2012, 02:16 PM
  5. Count Items by Time Period
    By pawslover in forum Queries
    Replies: 1
    Last Post: 11-15-2010, 03:57 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