?
Solved

Access 2007, VBA: Question about listboxes, multiple selections

Posted on 2011-02-15
10
Medium Priority
?
1,174 Views
Last Modified: 2012-05-11
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 (in multi-select mode simple) 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 when a user attempts to deselect his or her listbox choice the entire field nst is cleared.  The code for the list boxes right now is as follows:

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

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
0
Comment
Question by:Bevos
  • 5
  • 4
10 Comments
 
LVL 85
ID: 34901893
Did you copy/paste this? If so, you've got a type in the main Else section, I believe:

If InStr(rst, ",") > 0 Then

I would think that "rst" should be "nst"
0
 

Author Comment

by:Bevos
ID: 34902102
Hi, there was a typo there, thanks for spotting it!  However, after correcting this code I still have an issue.  Items that are deselected no longer cause the whole field to become erased, but they also are not removed from the notes field either.  Any thoughts?

Thank you
0
 

Author Comment

by:Bevos
ID: 34902113
This issue only takes place if multiple selections are made in the list box.  If a single selection is made, it can be removed by clicking that entry again.
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 34902129
the codes should work as they are (exclude the typo).

is the text string listed in the [notes] control coming only from list58?
0
 

Author Comment

by:Bevos
ID: 34902174
Hi again capricorn1,  no it is coming from several list boxes.  I put the code here as an example not thinking that it would be effected.  Currently there are 12 list boxes using the code from above.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 34902214
can you upload a copy of the db.
0
 

Author Comment

by:Bevos
ID: 34902247
Sure, thanks!
Example---Copy.accdb
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 2000 total points
ID: 34902398
0
 

Author Comment

by:Bevos
ID: 34902462
Works completely ... I'm checking out the VBA code and it seems the same as what's posted above.  Mind if I ask how you addressed this?
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 34902765
<I'm checking out the VBA code and it seems the same as what's posted above.>

yes that is how all the codes from the listboxes afterupdate event should look like.
0

Featured Post

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Access has a limit of 255 columns in a single table; SQL Server allows tables with over 255 columns, but reading that data is not necessarily simple.  The final solution for this task involved creating a custom text parser and then reading…
Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses
Course of the Month16 days, 10 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question