Results 1 to 7 of 7
  1. #1
    Timo is offline Novice
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    7

    Taking values from a list-box for further queries

    Hi everybody,

    I would like use the values from a multiple selection in a list-box for further queries. Therefore, I have started to use a button to control selected values from the list-box (named: Automatisierungen):


    Private Sub Befehl_Click()

    Dim varItem As Variant, strq As String


    strq = ""

    For Each varItem In Me.Automatisierungen.ItemsSelected

    strq = strq & "OR qry_value.value ='" & Me.Automatisierungen.ItemData(varItem) & "' "

    Next varItem

    Debug.Print strq



    If click on e.g. two items in my list-box (SM and SMC), I will get the following result by using “Debug.Print”:




    OR qry_value.value ='SM' OR qry_value.value ='SMC'



    Thus I think it basically works, but I would like to have just the results “SM” OR “SMC” without the whole code.

    Do you have any ideas, what I have to change?


    Best regards,
    Timo

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,550
    Try NOT to use multi-pick list boxes, it takes a LOT of programming which may not suit well for novice programmers.
    INSTEAD build a form so the user can dbl-click items in a list. This runs an append query that puts it in a table.
    This table can be joined to the main data table to pull only from the picked items.
    Attached Thumbnails Attached Thumbnails pick state-lbl.png  

  3. #3
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Not sure it would be a usable string, but basically you just need to drop the unwanted parts from the literal string and trim the leading OR after the string is built.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  4. #4
    Timo is offline Novice
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    7
    Thank you very much for your replies.

    Unfortunately, I think I need the structure of list-boxes and multiple selections to have an appropriate layout at the end.
    Maybe it’s possible to take this string into another query. I’m going to try this. Then it would be fine to have this whole code.
    But I think the problem with the “OR” at the beginning remains. Do have any ideas how to connect all the selected Items with an “OR” (like I already have), but do not to start with an “OR”?
    I tried to connect the code with a defined constat (a part of a query that remains always the same) with an "AND": myquery = const & strq.
    But the problem is that the two strings (the two queries) will be connected with an “OR”.

  5. #5
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,770
    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.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,652
    Quote Originally Posted by Timo View Post
    Do have any ideas how to connect all the selected Items with an “OR” (like I already have), but do not to start with an “OR”?
    Like I said, trim it off after you build it:

    strq = Mid(strq, 4)
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    Timo is offline Novice
    Windows 8 Access 2013
    Join Date
    Jul 2015
    Posts
    7
    Thanks a lot.
    I'm also not sure if I will get all the wished results, but the connection of two constant queries and this dynamic selection works in this way.

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

Similar Threads

  1. Replies: 4
    Last Post: 07-10-2014, 02:24 PM
  2. Replies: 7
    Last Post: 12-04-2013, 01:55 PM
  3. Replies: 2
    Last Post: 02-03-2013, 01:11 PM
  4. Replies: 3
    Last Post: 12-06-2011, 07:37 AM
  5. Replies: 3
    Last Post: 10-13-2011, 02:27 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