If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Display Modes |
#1
|
|||
|
|||
Clearing a multivalued combo box
In VBA, how do you clear a multivalued combo box?
Simply setting it to Null doesn't work. Thanks in advance, John |
#2
|
|||
|
|||
Clearing a multivalued combo box
This ought to work:
Dim varItem As Variant For Each varItem In Me.lstElevation.ItemsSelected Me.lstElevation.Selected(varItem) = 0 Next varItem Me.lstElevation.Requery -- Arvin Meyer, MCP, MVP http://www.datastrat.com http://www.mvps.org/access http://www.accessmvp.com "John Harrington" wrote in message ... In VBA, how do you clear a multivalued combo box? Simply setting it to Null doesn't work. Thanks in advance, John |
#3
|
|||
|
|||
Clearing a multivalued combo box
"John Harrington" wrote in message ... In VBA, how do you clear a multivalued combo box? Simply setting it to Null doesn't work. Thanks in advance, John Those multi-value listbox, or combo boxs are artually a realted table. You can use the folwling code: Private Sub cmdClear_Click() ' Clear all values... Dim rstDel As DAO.Recordset ' delete selected records... Set rstDel = Me.Recordset!FavColors.Value Do While rstDel.EOF = False rstDel.Delete rstDel.MoveNext Loop Me.Refresh End Sub -- Albert D. Kallal (Access MVP) Edmonton, Alberta Canada |
#4
|
|||
|
|||
Clearing a multivalued combo box
Thanks to both of you for your answers, but neither solution works (I
tried both and am pretty certain I tried them right). This one does, though: Me.MyMultiValue = Array() ' clears a multivalued combo box called MyMultiValue. Best regards, John |
#5
|
|||
|
|||
Clearing a multivalued combo box
"John Harrington" wrote in message
... In VBA, how do you clear a multivalued combo box? Simply setting it to Null doesn't work. I vaguely recall, but can't test it at the moment, that you can do it by assigning an empty array to the combo box. Something like Me.cboMultivalue = Array() However, I could be remembering this wrong. If you test it, please post back with the result. -- Dirk Goldgar, MS Access MVP Access tips: www.datagnostics.com/tips.html (please reply to the newsgroup) |
#6
|
|||
|
|||
Clearing a multivalued combo box
"John Harrington" wrote in message
... Thanks to both of you for your answers, but neither solution works (I tried both and am pretty certain I tried them right). This one does, though: Me.MyMultiValue = Array() ' clears a multivalued combo box called MyMultiValue. I'm glad that Dirk found something that works for you. The code I posted has been working daily for the last 8 years, and I can't imagine why it didn't work for you. -- Arvin Meyer, MCP, MVP http://www.datastrat.com http://www.mvps.org/access http://www.accessmvp.com |
#7
|
|||
|
|||
Clearing a multivalued combo box
"Arvin Meyer [MVP]" wrote in message
... I'm glad that Dirk found something that works for you. I think he found it on his own, just before I posted. The code I posted has been working daily for the last 8 years, and I can't imagine why it didn't work for you. Your code is for a multiselect list box, while John was dealing with a combo box bound to a multi-value field. -- Dirk Goldgar, MS Access MVP Access tips: www.datagnostics.com/tips.html (please reply to the newsgroup) |
#8
|
|||
|
|||
Clearing a multivalued combo box
Arvin
Could this be one of those instances when a bang ("!") is more appropriate than a dot (".")? It's seemed to me, over the years, that Access has gotten more and more finicky about having Me!MyOwnControl ... -- Regards Jeff Boyce Microsoft Access MVP Disclaimer: This author may have received products and services mentioned in this post. Mention and/or description of a product or service herein does not constitute endorsement thereof. Any code or pseudocode included in this post is offered "as is", with no guarantee as to suitability. You can thank the FTC of the USA for making this disclaimer possible/necessary. "Arvin Meyer [MVP]" wrote in message ... "John Harrington" wrote in message ... Thanks to both of you for your answers, but neither solution works (I tried both and am pretty certain I tried them right). This one does, though: Me.MyMultiValue = Array() ' clears a multivalued combo box called MyMultiValue. I'm glad that Dirk found something that works for you. The code I posted has been working daily for the last 8 years, and I can't imagine why it didn't work for you. -- Arvin Meyer, MCP, MVP http://www.datastrat.com http://www.mvps.org/access http://www.accessmvp.com |
#9
|
|||
|
|||
Clearing a multivalued combo box
"John Harrington" wrote in message
... Thanks to both of you for your answers, but neither solution works (I tried both and am pretty certain I tried them right). This one does, though: Me.MyMultiValue = Array() ' clears a multivalued combo box called MyMultiValue. There is been some confusing in this post as to multi-select vs that of multi-value.... The example code I have works for multi-value (curious..did the sample I posted compile???). -- Albert D. Kallal (Access MVP) Edmonton, Alberta Canada |
#10
|
|||
|
|||
Clearing a multivalued combo box
"Dirk Goldgar" wrote in message ... "Arvin Meyer [MVP]" wrote in message ... I'm glad that Dirk found something that works for you. I think he found it on his own, just before I posted. The code I posted has been working daily for the last 8 years, and I can't imagine why it didn't work for you. Your code is for a multiselect list box, while John was dealing with a combo box bound to a multi-value field. -- Dirk Goldgar, MS Access MVP Access tips: www.datagnostics.com/tips.html (please reply to the newsgroup) Hum, interesting, Arvin's code actually DOES work for a bound multi-value combo box. So, the following works for me: Dim varItem As Variant For Each varItem In Me.FavColors.ItemsSelected Me.FavColors.Selected(varItem) = 0 Next varItem Me.FavColors.Requery End Sub and: ' Clear all values... Dim rstDel As DAO.Recordset ' delete any possbile selected records... Set rstDel = Me.Recordset!FavColors.Value Do While rstDel.EOF = False rstDel.Delete rstDel.MoveNext Loop Me.Refresh and: Me.FavColors = Array() The above last use of the array function is new to me. I not even sure what exactly the Array() function without any parameters returns... -- Albert D. Kallal (Access MVP) Edmonton, Alberta Canada |
Thread Tools | |
Display Modes | |
|
|