[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Access 2007, VBA: Question about listboxes, multiple selections

Posted on 2011-02-15
10
Medium Priority
?
1,168 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
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…

650 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