Results 1 to 7 of 7
  1. #1
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368

    Trouble getting the right result from a query

    Hey guys,



    I have three unbound controls on my form :

    Number of keys
    Number of locks

    Serialnumber

    I want to check my database for serialnumbers that match my criteria, e.g. find 3 locks and 4 keys with matching serialnumers !
    In the unbound controls (keys and locks) i input the number of matching keys and locks i wanna check, and the serialnumer must reveal what the serialnumber of the first matching set is, if any.

    Any idea how i go about this ?
    I made a query but it seems to only find one matching criteria (locks OR keys) not both.

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    if you only search on the serial, how many locks/keys does it return?

  3. #3
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    You didn't describe the table(s) structure(s).
    And it would help to see some data and expected results.

    Maybe:

    If the table names are
    tblLocks: fields Locks, SN
    tblKeys: fields Keys, SN


    qryLockCount: a totals query counting locks, grouped by serial number
    Code:
    SELECT Count(tblLocks.Locks) AS CountOfLocks, tblLocks.SN
    FROM tblLocks
    GROUP BY tblLocks.SN;
    qryKeysCount: a totals query counting keys, grouped by serial number
    Code:
    SELECT Count(tblKeys.Keys) AS CountOfKeys, tblKeys.SN
    FROM tblKeys
    GROUP BY tblKeys.SN;
    qryKeysLocks: another query based on the first 2 queries
    Code:
    SELECT qryKeysCount.CountOfKeys, qryLockCount.CountOfLocks, qryKeysCount.SN
    FROM qryKeysCount INNER JOIN qryLockCount ON qryKeysCount.SN = qryLockCount.SN;

    Final query:
    Code:
    SELECT qryKeysLocks.SN, qryKeysLocks.CountOfLocks, qryKeysLocks.CountOfKeys
    FROM qryKeysLocks
    WHERE (((qryKeysLocks.CountOfLocks)=[Forms]![FormName].[tbLocks]) AND ((qryKeysLocks.CountOfKeys)=[Forms]![FormName].[tbKeys]));

    "tbLocks" = the unbound control on form for the number of locks ("tb" = Text box)
    Change "FormName" and the unbound text box control names to your names.

  4. #4
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    Hi Ssanfu,

    Thanks for taking the time to help.
    Yes, i didnt provide enough information i guess.

    I have one table (tblSluitsystemen) with the field SerieNummer and field Soort.
    The field SerieNummer holds the serial number of the locks or keys.
    The field Soort holds the information if its a lock or a key. So it is either a 'Cilinder' (Dutch for lock) or a 'Sleutel' (Dutch for key)

    Offcourse, a serialnumber is NOT unique. You might have a lock with a matching key. Or multiple locks where the same key fits.
    The whole point of me doing this is because we have a stock with locks and keys, and i want to be able to find specific needs asked withing the buisiness.
    So if they ask me for 3 locks with the same serial number, and 4 matching keys, i want to check if they are in the database (and thus in stock).

    Hence the unbound controls :

    "fldAantalDuplicatenCilinders" <----translated fldNumberDuplicateLocks"
    "fldAantalDuplicatenSleutels" <----translated fldNumberDuplicateKeys"

    If i fill in the number of locks im looking for in the first field, and the number of keys im lokking for in the second, and press a search button.
    I want the third unbound control :

    "fldBeschikbaarSerieNummer" <----translated fldAvailableSerialNumber"

    to display if there is a match, and if so what is the serial number.
    Once i know what the serial number is, i can go to the stock in our basement and look for the specific set.

    I hope i explained it well enough. Ive been trying to find the solution myself for days but im getting nowhere, although it doesnt seem all the difficult ..

  5. #5
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Maybe something like this?

    Enter
    3 for Aantal Duplicaten Cilinders
    4 for Aantal Duplicaten Sleutels
    Click Find button
    Attached Files Attached Files

  6. #6
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows 7 32bit Access 2010 32bit
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    I had to tweak it to my situation a little bit, but that helps me alot.
    The only thing is, how can i made the result not "=" but ">=" ?

  7. #7
    ssanfu is offline Master of Nothing
    Windows 7 32bit Access 2010 32bit
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Did you try adding the ">=" to be beginning of each of the criteria??
    Click image for larger version. 

Name:	Presentation1.png 
Views:	4 
Size:	34.9 KB 
ID:	33476

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

Similar Threads

  1. Replies: 1
    Last Post: 09-14-2017, 10:19 AM
  2. Replies: 7
    Last Post: 03-23-2017, 10:26 AM
  3. having trouble making a text box equal to a query result
    By NightWalker in forum Programming
    Replies: 16
    Last Post: 02-14-2017, 05:33 PM
  4. Replies: 8
    Last Post: 05-16-2012, 09:30 AM
  5. Trouble with Query
    By jbarrum in forum Access
    Replies: 1
    Last Post: 01-13-2010, 04:10 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