By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
429,471 Members | 722 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 429,471 IT Pros & Developers. It's quick & easy.

how to reset a listbox after selection

P: n/a
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
Share this Question
Share on Google+
8 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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.