Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    eagle670 is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2014
    Posts
    21

    Query does not show selections from list box

    I have a list box (SUB CATEGORY) on my form where I can select multiple items. I have a query (Final) that has this field in it.

    Problem - I cannot seem to get the list box selections to appear in the query results. Please give me an idea of either what the "Criteria" should look like or maybe some code that I can try. Thanks

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

  3. #3
    burrina's Avatar
    burrina is offline VIP
    Windows 8 Access 2010 32bit
    Join Date
    Oct 2012
    Location
    Freeport,Texas
    Posts
    1,383
    Here is an example of code that enters the listbox vale selected and puts it into the field named EmailTo



    If Me.lstlist.ItemsSelected.Count = 0 Then
    MsgBox "You must select at least 1 Item"
    Exit Sub
    End If





    Dim strEmail As String
    Dim varItem As Variant
    For Each varItem In lstlist.ItemsSelected

    strEmail = strEmail & lstlist.Column(2, varItem) & ";"

    Next varItem
    If strEmail > "" Then
    strEmail = Left(strEmail, Len(strEmail) - 1)
    End If




    Me.EmailTo.Value = strEmail



    Me.Dirty = False
    Me.Refresh

    HTH

  4. #4
    eagle670 is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2014
    Posts
    21
    I have tried to add the code to the command buttons "On Click" procedure, but for some reason I cannot get it to work.

    Please help me out with editing the code to conform with my info.

    My field name in my query is "Sub Desc" . My list box is "list81". My command button is "cmdpreview", named "Preview"


    Please confirm that this code is placed in the OnClick procedure of the command button

    Also, is there anything that needs to be placed the field of the query criteria.

    Thanks for your help!

  5. #5
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    This is a different approach.

    1) Build a "SUB CATEGORY" table with an extra Yes/No field.
    2) When it is being selected from the form, then set Yes to that records.
    3) Build a SELECT query join the "SUB CATEGORY" table and select only Yes in that extra field.

  6. #6
    eagle670 is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2014
    Posts
    21
    I created a SUB CATEGORY table and have added another field titled "YES/NO" (What do I set the data type for this field?) Right now when my list box comes up it is showing the SUB CATEGORY in one column and "NO" in the other column. I don't know what to do to get the option of a YES/NO selection.

    What do I have to put in the criteria section of the query that contains the control field?

    Thanks for your help!

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

  8. #8
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    "Yes/No" is a data type. I would rename the field called "Included", "Checked", or "Flag" or something other than "YES/NO". But, it is a personal preference.

    In form list box "Click" event, you have to put Yes in the newly created field.

    I will post a sample code when I find it.

  9. #9
    lfpm062010 is offline Competent Performer
    Windows 7 64bit Access 2010 64bit
    Join Date
    Oct 2013
    Location
    US
    Posts
    415
    Use a subform instead of listbox. Easier coding. See attached for example.
    Test.accdb

  10. #10
    eagle670 is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2014
    Posts
    21
    Here is a pic of what I am getting on the form list box. I called my new field "Checked" and in the properties area I typed in the text "Yes" in the 'OnClick" procedure. I have done nothing to the query that contains the "Sub Category" field as of yet.
    Please advise.

  11. #11
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,649
    No picture attached to your post. Why would you type "Yes" in 'OnClick' procedure?
    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.

  12. #12
    eagle670 is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2014
    Posts
    21
    I have created a sub-form as suggested. I like this approach better than the other, however it still does will not communicate with the query. I am getting an error, please see attached.Click image for larger version. 

Name:	screen shot.jpg 
Views:	6 
Size:	48.1 KB 
ID:	16888

  13. #13
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,649
    I think with this approach the query does not have to look at the form. The form has set the value of Yes/No field in table. Just apply criteria in query to select all records where that field is Yes.

    Then when the procedure is complete, run an UPDATE query to set all the records back to No.

    What is purpose of the query? What are you really trying to accomplish - create a shopping list?
    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.

  14. #14
    eagle670 is offline Novice
    Windows XP Access 2007
    Join Date
    Jun 2014
    Posts
    21
    The query is running a report that tells me what products are missing out of my merchandising plan.

    So, In the criteria field, do you go through the "build" process? I am not sure how to tell it to select all that is checked "Yes"

  15. #15
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    53,649
    In query builder, type True under the field on the Criteria row.

    SELECT * FROM tableORquery WHERE fieldname = True;
    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.

Page 1 of 2 12 LastLast
Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 5
    Last Post: 04-25-2013, 01:55 AM
  2. Copy list box selections to another list box
    By Gotham_Knight in forum Forms
    Replies: 1
    Last Post: 03-07-2013, 10:40 AM
  3. List Box Selections
    By MJeanBap in forum Forms
    Replies: 10
    Last Post: 04-05-2012, 06:26 AM
  4. Multiple Selections from a List Box
    By oleBucky in forum Forms
    Replies: 4
    Last Post: 05-06-2011, 08:24 AM
  5. Clear selections from a List Box?
    By Dreams2Fly in forum Forms
    Replies: 3
    Last Post: 03-28-2011, 02:25 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