Results 1 to 3 of 3
  1. #1
    skydivetom is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Feb 2019
    Posts
    1,046

    Multi-select listbox to output n values (as IN string) into query


    Good morning:

    I'd like to get some assistance with tweaking an existing VBA function which would allow me to pass *multiple* listbox items into a stored query.

    Current Process:
    - Forms by default
    - Listbox = multi-select; either drag across items OR hold CTRL key to select non-consecutive items
    - Click on command button "Open Query"
    - Now, regardless of how many items/values were selected in the listbox, the query currently outputs only the last selected value

    What I Need Instead:
    - Modify the existing VBA so that I created a string of values in my query criteria (via the IN method)
    - For instance, if I were to select {mail, auth, syslog, ftp}, I then would want to send *In ('mail','auth','syslog','ftp')* into the query's criteria

    How does the VBA need to be modified to achieve the envisioned outcome?

    Thank you,
    EEH

    P.S. Please see attached sample ACCDB
    Attached Thumbnails Attached Thumbnails VBA_Output.jpg  
    Attached Files Attached Files

  2. #2
    moke123's Avatar
    moke123 is offline Me.Dirty=True
    Windows 11 Office 365
    Join Date
    Oct 2012
    Location
    Ma.
    Posts
    1,654
    see my getLBX function in your old thread https://www.accessforums.net/showthr...397#post501397

    you can pass the argument for the second column and delimit with quotes.

    something like
    Code:
    qdf.SQL = "Select * from T102_Syslog_SampleData where KEYWORD in (" & getLBX(Me.lstSyslogKeywords, 1, , """") & ") order by KeyWord"
    If this helped, please click the star * at the bottom left and add to my reputation- Thanks

  3. #3
    skydivetom is offline VIP
    Windows 8 Access 2010 64bit
    Join Date
    Feb 2019
    Posts
    1,046
    ** UPDATED RESPONSE **

    moke123 -- thank you for the assistance. I plugged the lbx function into a module and, using the updated QDF.SQL, it now works like a charm. 1000 thanks!!

    Cheers,
    EEH

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

Similar Threads

  1. Replies: 4
    Last Post: 11-10-2019, 11:10 PM
  2. Replies: 24
    Last Post: 08-08-2015, 09:19 AM
  3. Replies: 4
    Last Post: 09-23-2014, 08:39 AM
  4. Multi Select Listbox parameter for Query
    By KBAR12 in forum Programming
    Replies: 70
    Last Post: 03-26-2014, 11:22 AM
  5. Replies: 6
    Last Post: 11-02-2012, 12:48 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