Results 1 to 6 of 6
  1. #1
    REAbernathy is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jul 2012
    Posts
    46

    I have two multi select list boxes where I need to be able to select all or some of t

    Good Afternoon,



    I have created a form and on my form i have 2 list boxes and they are named Error Code Description and the other is Error Codes and Corrections Resoultions. I wrote a query to import the information that i need for both list boxes. I want to be able to allow the users to choose multiple items in each list box if that is required and then this information will be added to a Table called TrackingSystem3. The problem that I am having is if i only choose one item it works just fine however when i choose 2,3 or 4 nothing shows up in the database.

    I apologize, but I'm not as tech savy/smart as most and I've not used VBA so I'm not able to translate someone else’s code to suite my purposes.

    I wanted to attached a copy of my database in order for you to see what I'm trying to accomplish. But I am unable to upload any files to this forum site, I keep getting an error message.

    Thanks for any assistance that you can give me
    Attached Files Attached Files

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    What error is the upload throwing?

    You were able to successfully upload the zip with Word document. Why not Access db?

    A multi-select list or combobox can be used to automatically populate a multi-value field.

    VBA code will be required to use the selected values to filter records. Review: http://allenbrowne.com/ser-50.html
    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
    REAbernathy is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jul 2012
    Posts
    46
    I dont quite understand what you are asking me. It's not giving me any error message at all what it's doing is when i go to my form and select more than one choice for the follwoing fields ErrorCodeDescription and ErrorCodesandCorrections that information that was selected for those two fields are not showing up in the database. What I am trying to do is allow my user to choose more than one selection in either of the listboxes that have been created then that information is stored into a datatbase that I created. Per my screenshot the two fields in question are ErrorCodeDescription and ErrorCodesandCorrections. I haven't used VB so pretty much I am new to this. If anyone can help me i would greatly appericate it....Thanking you guys in advance

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    A multi-select combo or list box can be used to:

    1. save the selected items to a multi-value field that the box is bound to

    or

    2. VBA can cycle through the box list and use the selected items to do something. That something can be a variety of things, one of which is to save records to table, another is to build filter criteria for a report. The referenced link demonstrates the latter but can be adapted to the first. The core code is the looping through the box list. Within the loop you can do what you want with the selected item(s). In your case you want to create a record. Code for that could be something like (assumes the field is text type):
    CurrentDb.Execute "INSERT INTO tablename(fieldname) VALUES('" & value from combobox & "')"

    You said you got an error message when you tried to upload file. That is the error I was asking about.
    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.

  5. #5
    REAbernathy is offline Advanced Beginner
    Windows 7 64bit Access 2007
    Join Date
    Jul 2012
    Posts
    46
    Super Moderator,

    Thanks for the information and i really appericate your response however I am new to the VBA world so where can i find some code that will help me fix this problem that I am having. I have the following code that i found and i dont have any idea if it works or not and also where do i put this code (told you i was new to this). I feel like a deer in headlights and I dont have any idea of how to get out of the way before i get hit....Here is the code and Please tell me if I am on the right path or not. And again Thank You so much for your help and assistance.

    Private Sub ErrorCodeDescriptionList88_Click()
    Option Compare Database
    Option Explicit
    Private Sub Form_Current()
    Dim oItem As Variant
    Dim bFound As Boolean
    Dim sTemp As String
    Dim sValue As String
    Dim sChar As String
    Dim iCount As Integer
    Dim iListItemsCount As Integer
    sTemp = Nz(ErrorCodeDescription.Value, " ")
    iListItemsCount = 0
    bFound = False
    iCount = 0
    Call clearListBox
    For iCount = 1 To Len(sTemp) + 1
    sChar = Mid(sTemp, iCount, 1)
    If StrComp(sChar, ",") = 0 Or iCount = Len(sTemp) + 1 Then
    bFound = False
    Do
    If StrComp(Trim(ErrorCodeDescription.ItemData(iListIt emsCount)), Trim(sValue)) = 0 Then
    ErrorCodeDescription.Selected(iListItemsCount) = True
    bFound = True
    End If
    iListItemsCount = iListItemsCount + 1
    Loop Until bFound = True Or iListItemsCount = ErrorCodeDescription.ListCount
    sValue = ""
    Else
    sValue = sValue & sChar
    End If
    Next iCount
    End Sub
    End Sub

  6. #6
    June7's Avatar
    June7 is offline VIP
    Windows XP Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,928
    Review http://office.microsoft.com/en-us/ac...010341717.aspx

    Also, review the link on debugging at bottom of my post.

    Not sure what the code you show is supposed to do but it is not saving records. I have given you reference to example code that can be adapted to your situation as well as the code needed to save record. The boxes would be unbound.
    I don't know your db so can't give specifics but something like:
    Code:
        'Loop through the ItemsSelected in the list box.    
        With Me.lstCategory
            For Each varItem In .ItemsSelected
                If Not IsNull(varItem) Then
                   CurrentDb.Execute "INSERT INTO tablename(fieldname) VALUES('" & .Column(1, varItem) & "')"
                End If
            Next
        End With
    Are these listboxes on form that is bound to the table you want the listbox selections saved to? As stated, really don't know enough about your db.

    I never use them, but maybe what you really want is a multi-value field. http://office.microsoft.com/en-us/ac...001233722.aspx

    Another consideration is instead of multi-select listboxes, maybe subform would serve this need.
    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.

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

Similar Threads

  1. Multiple Multi-select boxes on one form
    By bujaman in forum Forms
    Replies: 8
    Last Post: 01-20-2012, 01:48 PM
  2. 2 multi select list boxes on one search form
    By woodey2002 in forum Forms
    Replies: 2
    Last Post: 11-05-2010, 12:44 PM
  3. Replies: 1
    Last Post: 10-22-2010, 10:11 AM
  4. Multi-select List Boxes
    By Rawb in forum Programming
    Replies: 6
    Last Post: 09-21-2010, 09:02 AM
  5. Replies: 1
    Last Post: 03-01-2009, 09:53 AM

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