[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 449
  • Last Modified:

Access 2007, VBA: Question about listboxes, multiple selections

Hello, I have been working on a database with the help of some of the users of experts exchange and I was hoping I could get some comments about how to change how my form's list boxes are functioning.  I have several list boxes all of which pass their values to a variable nst and then this value is passed onto the [notes] field on my form/table.  The way the list boxes function now works pretty well, but I would like a user to be able to de-select a list choice in the listbox.  That is to say if he or she clicks one of the items it removes it as a selection.  The code for the list boxes right now is as follows:

Private Sub List58_AfterUpdate()

With Me.List58
If .Selected(.ListIndex) = True Then
    If nst = "" Then
        nst = .Column(0, .ListIndex)
        Else
                  If InStr(nst, .Column(0, .ListIndex)) = 0 Then
            nst = nst & ", " & .Column(0, .ListIndex)
        End If

    End If
   
    Else
    If InStr(rst, ",") > 0 Then
        If InStr(nst, .Column(0, .ListIndex)) = 1 Then
            nst = Replace(nst, .Column(0, .ListIndex) & ",", "")
        Else
            nst = Replace(nst, "," & .Column(0, .ListIndex), "")
        End If
        Else
        nst = ""
    End If
End If

End With
Me.[Notes] = nst
End Sub

Does anyone know if it is possible to accomplish what I have requested, and if so how should the above code be modified?

Thanks in advance for any comments,
Bevo
0
Bevos
Asked:
Bevos
1 Solution
 
Rey Obrero (Capricorn1)Commented:
first change the multi select property to simple

use this revised codes, copy and paste


Private Sub List58_AfterUpdate()

With Me.List58
If .Selected(.ListIndex) = True Then
    If nst = "" Then
        nst = .Column(0, .ListIndex)
        Else
                  If InStr(nst, .Column(0, .ListIndex)) = 0 Then
            nst = nst & ", " & .Column(0, .ListIndex)
        End If

    End If
   
    Else
    If InStr(rst, ",") > 0 Then
        If InStr(nst, .Column(0, .ListIndex)) = 1 Then
            nst = Replace(nst, .Column(0, .ListIndex) & ", ", "")
        Else
            nst = Replace(nst, ", " & .Column(0, .ListIndex), "")
        End If
        Else
        nst = ""
    End If
End If

End With
Me.[Notes] = nst
End Sub

Open in new window

0
 
BevosAuthor Commented:
This was perfect. Thanks cap!
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now