A Microsoft Office (Excel, Word) forum. OfficeFrustration

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.

Go Back   Home » OfficeFrustration forum » Microsoft Access » Using Forms
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Clearing a multivalued combo box



 
 
Thread Tools Display Modes
  #1  
Old December 31st, 2009, 07:14 PM posted to microsoft.public.access.forms
John Harrington
external usenet poster
 
Posts: 30
Default 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  
Old December 31st, 2009, 07:51 PM posted to microsoft.public.access.forms
Arvin Meyer [MVP][_2_]
external usenet poster
 
Posts: 2,310
Default 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  
Old December 31st, 2009, 07:54 PM posted to microsoft.public.access.forms
Albert D. Kallal
external usenet poster
 
Posts: 2,874
Default 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  
Old December 31st, 2009, 09:15 PM posted to microsoft.public.access.forms
John Harrington
external usenet poster
 
Posts: 30
Default 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  
Old December 31st, 2009, 09:16 PM posted to microsoft.public.access.forms
Dirk Goldgar
external usenet poster
 
Posts: 2,529
Default 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  
Old January 1st, 2010, 02:09 AM posted to microsoft.public.access.forms
Arvin Meyer [MVP][_2_]
external usenet poster
 
Posts: 2,310
Default 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  
Old January 1st, 2010, 07:18 AM posted to microsoft.public.access.forms
Dirk Goldgar
external usenet poster
 
Posts: 2,529
Default 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  
Old January 1st, 2010, 01:41 PM posted to microsoft.public.access.forms
Jeff Boyce
external usenet poster
 
Posts: 1,555
Default 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  
Old January 3rd, 2010, 02:42 AM posted to microsoft.public.access.forms
Albert D. Kallal
external usenet poster
 
Posts: 2,874
Default 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  
Old January 3rd, 2010, 03:26 AM posted to microsoft.public.access.forms
Albert D. Kallal
external usenet poster
 
Posts: 2,874
Default 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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 06:27 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.