Results 1 to 14 of 14
  1. #1
    CORINEREYES is offline Novice
    Windows 11 Access 2016
    Join Date
    Jan 2023
    Posts
    18

    Paramater Query , Applying Criteria Multiple Numbers

    Hi,




    Good day to everyone.


    I have this issues applying criteria to a Number. Example a user will input multiple numbers (employee numbers) to the parameter query in a query in access. How do i do it? I have searched for many topics however it only discuss text and not numbers.


    I have attached a screenshot for reference.


    PLEASE HELP?


    Thank you in advance.


    Maria
    Attached Thumbnails Attached Thumbnails criteria.jpg  

  2. #2
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Use IN() for the criteria.
    Always better to use a form for criteria, as then it can be validated before use.
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  3. #3
    CORINEREYES is offline Novice
    Windows 11 Access 2016
    Join Date
    Jan 2023
    Posts
    18
    Quote Originally Posted by Welshgasman View Post
    Use IN() for the criteria.
    Always better to use a form for criteria, as then it can be validated before use.
    Code:
    In ([Enter the ID values separated by commas:]) 


    I have used this function already but it does not work?

    this my SQL for the query

    Code:
    SELECT [Employee Details].[STAFF ID] INTO MultiTrans
    FROM [Employee Details]
    WHERE ((([Employee Details].[STAFF ID]) IN ([Enter the ID values separated by commas:])));

  4. #4
    Join Date
    Jan 2017
    Location
    Swansea,South Wales,UK
    Posts
    4,940
    Start off with a simple SELECT until you get it working.
    Small steps, one at a time.

    I cannot see why that would not work, I have used that syntax many times with out issues?

    Code:
    strRptQuery = "qryEmployeeHours"
    Set ctl = Me!lstDayType
    'Open the report with an OpenArgs value to get selected hours for employee
    ' Now select what type of day records from listbox
    If ctl.ItemsSelected.Count > 0 Then
        For Each varItem In ctl.ItemsSelected
            strParam = strParam & ctl.ItemData(varItem) & ","
        Next varItem
      Else
        MsgBox ("At least one Day Type is required")
        Exit Sub
    End If
    
    
    ' Need to pass the criteria as a string
    strParam = " IN (" & Left(strParam, Len(strParam) - 1) & ")"
    
    
    
    strParam = "[DateType]" & strParam
    DoCmd.OpenReport "rptHours", acViewReport, , strParam, , "Selected"
    Please use # icon on toolbar when posting code snippets.
    Cross Posting: https://www.excelguru.ca/content.php?184
    Debugging Access: https://www.youtube.com/results?sear...bug+access+vba

  5. #5
    Join Date
    May 2018
    Location
    Living in Scotland UK
    Posts
    1,566
    I would suggest you explain what you are trying to do with your database.

    From your screenshot you have multiple tables for Employee Details?
    You can PM me if you need further help.
    Good Reading https://docs.microsoft.com/en-gb/off...on-description

  6. #6
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    you can't use parameters in that way - WGM's suggestion provides a filter which you can't do within the context of a query

    Only way would be to use the eval function - and this assumes the staff id is numeric and not text

    Code:
    WHERE eval("" & [STAFF ID] & " IN (" & [Enter the ID values separated by commas:] & ")")=True
    However this is a very risky way of using a query - what if the user misses a comma?, types the wrong number?

  7. #7
    Micron is offline Virtually Inert Person
    Windows 10 Access 2016
    Join Date
    Jun 2014
    Location
    Ontario, Canada
    Posts
    12,801
    IMO to use IN for this and do it reliably would be to multi select from a form listbox. If there would be many to be chosen and that would present an issue due to scrolling through a list, then a pair of listboxes and the ability to move selected items to the "chosen" listbox is another way. However, using listbox(es) means that the sql needs to be constructed in vba.
    The more we hear silence, the more we begin to think about our value in this universe.
    Paraphrase of Professor Brian Cox.

  8. #8
    CORINEREYES is offline Novice
    Windows 11 Access 2016
    Join Date
    Jan 2023
    Posts
    18
    Quote Originally Posted by mike60smart View Post
    I would suggest you explain what you are trying to do with your database.

    From your screenshot you have multiple tables for Employee Details?
    Hi!

    Those are only previous tables that i do not want to delete, this is my test database only.

    The query in the picture is an Append query, it takes records from a database named Employee Details and appends the records in a table named MultiTrans by a user entering the employee number he/she may wish. However a parameter in the criteria can only hold 1 number. I would like for a user to input as many numbers as possible.

  9. #9
    CORINEREYES is offline Novice
    Windows 11 Access 2016
    Join Date
    Jan 2023
    Posts
    18
    Quote Originally Posted by CJ_London View Post
    you can't use parameters in that way - WGM's suggestion provides a filter which you can't do within the context of a query

    Only way would be to use the eval function - and this assumes the staff id is numeric and not text

    Code:
    WHERE eval("" & [STAFF ID] & " IN (" & [Enter the ID values separated by commas:] & ")")=True

    However this is a very risky way of using a query - what if the user misses a comma?, types the wrong number?

    Hi!

    This works perfectly fine! I will have to dealt later on if a user has mistakes in entering.

    Thank you so much for the help!

  10. #10
    CORINEREYES is offline Novice
    Windows 11 Access 2016
    Join Date
    Jan 2023
    Posts
    18
    Thanks all for the suggestions, i will go through all of them. thanks again for the guidance,

  11. #11
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    A little unusual to have 25 tables of employee details.
    You may have some normalization to do.
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  12. #12
    CJ_London is online now VIP
    Windows 10 Access 2010 32bit
    Join Date
    Mar 2015
    Posts
    11,430
    answered in post#8

  13. #13
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    Quote Originally Posted by CORINEREYES View Post
    Hi!

    This works perfectly fine! I will have to dealt later on if a user has mistakes in entering.

    Thank you so much for the help!
    It's not a question of "if" they're going to make mistakes. They certainly will.

    As already suggested, A multi-select list box or a pick list are some of the best ways to keep users from entering bad data.

    here's an example of how to generate the "In Clause"
    Attached Files Attached Files
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  14. #14
    CORINEREYES is offline Novice
    Windows 11 Access 2016
    Join Date
    Jan 2023
    Posts
    18
    Quote Originally Posted by moke123 View Post
    It's not a question of "if" they're going to make mistakes. They certainly will.

    As already suggested, A multi-select list box or a pick list are some of the best ways to keep users from entering bad data.

    here's an example of how to generate the "In Clause"
    Hi moke123, thank for the examples, i will incorporate this to my project if necessary.

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

Similar Threads

  1. applying criteria to 2 fields in different tables
    By dawnnolan54 in forum Queries
    Replies: 6
    Last Post: 09-02-2015, 04:01 PM
  2. Using Between and IIF in a query paramater
    By todmac in forum Queries
    Replies: 6
    Last Post: 04-10-2015, 06:43 PM
  3. Query Paramater Connection
    By magicmike92 in forum Queries
    Replies: 20
    Last Post: 08-13-2013, 02:57 PM
  4. Apply Filter 2 criteria not applying
    By ahightower in forum Forms
    Replies: 4
    Last Post: 07-28-2011, 03:31 PM
  5. Replies: 2
    Last Post: 05-09-2011, 06:45 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