469,619 Members | 2,113 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,619 developers. It's quick & easy.

how to reset a listbox after selection

I have a form that allows the user to selct items from a listbox and combo
box.

how do I reset them ready for the next set of entries. I thought I would
have a clear button.

regards in advance.

Peter
Nov 13 '05 #1
8 22939
For a combo box or a single-selection list box, just set the value to Null,
e.g.:
Me.MyCombo = Null

To clear a multi-select list box

Function ClearList(lst As ListBox) As Boolean
If lst.MultiSelect = 0 Then
lst = Null
Else
For Each varItem In lst.ItemsSelected
lst.Selected(varItem) = False
Next
End If
End Function

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Peter Bailey" <pe*********@andaluz.fsbusiness.co.uk> wrote in message
news:ci**********@news7.svr.pol.co.uk...
I have a form that allows the user to selct items from a listbox and combo
box.

how do I reset them ready for the next set of entries. I thought I would
have a clear button.

Nov 13 '05 #2
thanks Allen, it must be early in australia.
"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:41***********************@per-qv1-newsreader-01.iinet.net.au...
For a combo box or a single-selection list box, just set the value to Null, e.g.:
Me.MyCombo = Null

To clear a multi-select list box

Function ClearList(lst As ListBox) As Boolean
If lst.MultiSelect = 0 Then
lst = Null
Else
For Each varItem In lst.ItemsSelected
lst.Selected(varItem) = False
Next
End If
End Function

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Peter Bailey" <pe*********@andaluz.fsbusiness.co.uk> wrote in message
news:ci**********@news7.svr.pol.co.uk...
I have a form that allows the user to selct items from a listbox and combo box.

how do I reset them ready for the next set of entries. I thought I would
have a clear button.


Nov 13 '05 #3
Me.ListDOS.Enabled = True

ClearList (me.ListDOS)

When I call the function it gives error 424 object required, not sure why as
I think I am passing the listbox ok.
"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:41***********************@per-qv1-newsreader-01.iinet.net.au...
For a combo box or a single-selection list box, just set the value to Null, e.g.:
Me.MyCombo = Null

To clear a multi-select list box

Function ClearList(lst As ListBox) As Boolean
If lst.MultiSelect = 0 Then
lst = Null
Else
For Each varItem In lst.ItemsSelected
lst.Selected(varItem) = False
Next
End If
End Function

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Peter Bailey" <pe*********@andaluz.fsbusiness.co.uk> wrote in message
news:ci**********@news7.svr.pol.co.uk...
I have a form that allows the user to selct items from a listbox and combo box.

how do I reset them ready for the next set of entries. I thought I would
have a clear button.


Nov 13 '05 #4
Which line gives the error?

Does the code compile? (Compile on Debug menu)

--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.

"Peter Bailey" <pe*********@andaluz.fsbusiness.co.uk> wrote in message
news:ci**********@news5.svr.pol.co.uk...
Me.ListDOS.Enabled = True

ClearList (me.ListDOS)

When I call the function it gives error 424 object required, not sure why
as
I think I am passing the listbox ok.
"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:41***********************@per-qv1-newsreader-01.iinet.net.au...
For a combo box or a single-selection list box, just set the value to

Null,
e.g.:
Me.MyCombo = Null

To clear a multi-select list box

Function ClearList(lst As ListBox) As Boolean
If lst.MultiSelect = 0 Then
lst = Null
Else
For Each varItem In lst.ItemsSelected
lst.Selected(varItem) = False
Next
End If
End Function
"Peter Bailey" <pe*********@andaluz.fsbusiness.co.uk> wrote in message
news:ci**********@news7.svr.pol.co.uk...
>I have a form that allows the user to selct items from a listbox and combo > box.
>
> how do I reset them ready for the next set of entries. I thought I
> would
> have a clear button.

Nov 13 '05 #5
Allen Browne wrote:
Which line gives the error?

Does the code compile? (Compile on Debug menu)


I would think that if the person declared varItem it would work.
Nov 13 '05 #6
It fails on this :ClearList (me.ListDOS)

I couldnt compile as you said as it was picking up a mountain of other
things. (I didnt design the database I am just adding a function to it)
regards
Peter
"Salad" <oi*@vinegar.com> wrote in message
news:Nd*****************@newsread1.news.pas.earthl ink.net...
Allen Browne wrote:
Which line gives the error?

Does the code compile? (Compile on Debug menu)


I would think that if the person declared varItem it would work.

Nov 13 '05 #7
Does it compile?

As Salad pointed out, add this line to the top of the procedure:
Dim varItem As Variant

Then try:
Call ClearList (me.ListDOS)
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"Peter Bailey" <pe*********@andaluz.fsbusiness.co.uk> wrote in message
news:ci**********@news8.svr.pol.co.uk...
It fails on this :ClearList (me.ListDOS)

I couldnt compile as you said as it was picking up a mountain of other
things. (I didnt design the database I am just adding a function to it)
regards
Peter
"Salad" <oi*@vinegar.com> wrote in message
news:Nd*****************@newsread1.news.pas.earthl ink.net...
Allen Browne wrote:
> Which line gives the error?
>
> Does the code compile? (Compile on Debug menu)
>


I would think that if the person declared varItem it would work.

Nov 13 '05 #8
Thanks to everybody who assisted adding the variable fixed the problem.

regards
Peter
"Allen Browne" <Al*********@SeeSig.Invalid> wrote in message
news:41***********************@per-qv1-newsreader-01.iinet.net.au...
Does it compile?

As Salad pointed out, add this line to the top of the procedure:
Dim varItem As Variant

Then try:
Call ClearList (me.ListDOS)
--
Allen Browne - Microsoft MVP. Perth, Western Australia.
Tips for Access users - http://allenbrowne.com/tips.html
Reply to group, rather than allenbrowne at mvps dot org.
"Peter Bailey" <pe*********@andaluz.fsbusiness.co.uk> wrote in message
news:ci**********@news8.svr.pol.co.uk...
It fails on this :ClearList (me.ListDOS)

I couldnt compile as you said as it was picking up a mountain of other
things. (I didnt design the database I am just adding a function to it)
regards
Peter
"Salad" <oi*@vinegar.com> wrote in message
news:Nd*****************@newsread1.news.pas.earthl ink.net...
Allen Browne wrote:

> Which line gives the error?
>
> Does the code compile? (Compile on Debug menu)
>

I would think that if the person declared varItem it would work.


Nov 13 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by Dan Bass | last post: by
6 posts views Thread by Chris Leuty | last post: by
reply views Thread by Sanjin | last post: by
9 posts views Thread by zdrakec | last post: by
reply views Thread by devrayhaan | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.