Try to code a Command Button "Clear List"

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have set up a Find Records form for search the records listed in the table.
I have setup text boxes for searching the information with a Find Records
command button. I have also set up a command button called "Clear List". What
I am wanting is to clear the records in the list box so I can do another
search for a different set of records. If anyone can help with the correct
syntax and procedures (example would be a great help) I would really
appreciate it.
 
Save the function into a standard module.

Set the On Click property of your list box to:
=ClearList([List1])
where "List1" represents the name of your list box.

Function ClearList(lst As ListBox)
Dim varItem As Variant

If lst.MultiSelect = 0 Then
lst = Null
Else
For Each varItem In lst.ItemsSelected
lst.Selected(varItem) = False
Next
End If
End Function
 
I have one more code problem with the Find Records Command Button. Here is
what I have written so far:

Private Sub cmdFindRecords_Click()
On Error GoTo Err_cmdFindRecords_Click


Screen.PreviousControl.SetFocus
DoCmd.FindRecord(FindWhat, [Match As AcFindMatch = acEntire],
[MatchCase], [Search As AcSearchDirection = acSearchAll], [SearcAsFormatted],
[OnlyCurrent As AcFindfield = acCurrent], [FindFirst])=
Set Table!tblPrograms.FindRecords = " & "

Exit_cmdFindRecords_Click:
Exit Sub

Err_cmdFindRecords_Click:
MsgBox Err.Description
Resume Exit_cmdFindRecords_Click

End Sub

Allen Browne said:
Save the function into a standard module.

Set the On Click property of your list box to:
=ClearList([List1])
where "List1" represents the name of your list box.

Function ClearList(lst As ListBox)
Dim varItem As Variant

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

I am not sure what goes after = in the DoCmd.FindRecords statement. Thanks
for your help.
 
Allen:
I put the code in a module (Function to End Function) and then I put the
=ClearList([lstFindRecords]) On Click property, but it is still not working
when I push the Clear List command button. Do I need to do something in the
command button to trigger the module I wrote? Here is what I wrote in the
module:

Option Compare Database

Function ClearList(lst As ListBox)
Dim varItem As Variant

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 said:
Save the function into a standard module.

Set the On Click property of your list box to:
=ClearList([List1])
where "List1" represents the name of your list box.

Function ClearList(lst As ListBox)
Dim varItem As Variant

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.

Reply to group, rather than allenbrowne at mvps dot org.

j1eggert said:
I have set up a Find Records form for search the records listed in the
table.
I have setup text boxes for searching the information with a Find Records
command button. I have also set up a command button called "Clear List".
What
I am wanting is to clear the records in the list box so I can do another
search for a different set of records. If anyone can help with the correct
syntax and procedures (example would be a great help) I would really
appreciate it.
 
That should work. Are you getting an error message?

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

j1eggert said:
Allen:
I put the code in a module (Function to End Function) and then I put the
=ClearList([lstFindRecords]) On Click property, but it is still not
working
when I push the Clear List command button. Do I need to do something in
the
command button to trigger the module I wrote? Here is what I wrote in the
module:

Option Compare Database

Function ClearList(lst As ListBox)
Dim varItem As Variant

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 said:
Save the function into a standard module.

Set the On Click property of your list box to:
=ClearList([List1])
where "List1" represents the name of your list box.

Function ClearList(lst As ListBox)
Dim varItem As Variant

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


j1eggert said:
I have set up a Find Records form for search the records listed in the
table.
I have setup text boxes for searching the information with a Find
Records
command button. I have also set up a command button called "Clear
List".
What
I am wanting is to clear the records in the list box so I can do
another
search for a different set of records. If anyone can help with the
correct
syntax and procedures (example would be a great help) I would really
appreciate it.
 
Yes, when it runs it nests the function under "Private Sub
cmdClearList_Click()" which causes the error. I placed the End Sub under the
End Function, but it did not like that either.

Allen Browne said:
That should work. Are you getting an error message?

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

j1eggert said:
Allen:
I put the code in a module (Function to End Function) and then I put the
=ClearList([lstFindRecords]) On Click property, but it is still not
working
when I push the Clear List command button. Do I need to do something in
the
command button to trigger the module I wrote? Here is what I wrote in the
module:

Option Compare Database

Function ClearList(lst As ListBox)
Dim varItem As Variant

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 said:
Save the function into a standard module.

Set the On Click property of your list box to:
=ClearList([List1])
where "List1" represents the name of your list box.

Function ClearList(lst As ListBox)
Dim varItem As Variant

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


I have set up a Find Records form for search the records listed in the
table.
I have setup text boxes for searching the information with a Find
Records
command button. I have also set up a command button called "Clear
List".
What
I am wanting is to clear the records in the list box so I can do
another
search for a different set of records. If anyone can help with the
correct
syntax and procedures (example would be a great help) I would really
appreciate it.
 
Allen:
The error occurs when I press the Clear List button because I set the button
to the Expression Procedure. If I am not suppose to do that please let me
know.

Allen Browne said:
That should work. Are you getting an error message?

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

j1eggert said:
Allen:
I put the code in a module (Function to End Function) and then I put the
=ClearList([lstFindRecords]) On Click property, but it is still not
working
when I push the Clear List command button. Do I need to do something in
the
command button to trigger the module I wrote? Here is what I wrote in the
module:

Option Compare Database

Function ClearList(lst As ListBox)
Dim varItem As Variant

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 said:
Save the function into a standard module.

Set the On Click property of your list box to:
=ClearList([List1])
where "List1" represents the name of your list box.

Function ClearList(lst As ListBox)
Dim varItem As Variant

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


I have set up a Find Records form for search the records listed in the
table.
I have setup text boxes for searching the information with a Find
Records
command button. I have also set up a command button called "Clear
List".
What
I am wanting is to clear the records in the list box so I can do
another
search for a different set of records. If anyone can help with the
correct
syntax and procedures (example would be a great help) I would really
appreciate it.
 
The idea was to place the function in a standard module, so you can reuse it
for any list box on any form.

1. Click the Modules tab of the database window.
2. Click New. Access opens a new module.
3. Past the function in there.
4. Save the module with a name such as Module1.

Now set the On Click property to
=ClearList([lstFindRecords])

Or, if you want to set the On Click property to:
[Event Proceure]
then between the Private Sub... and End Sub lines, enter:
Call ClearList([lstFindRecords])

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

j1eggert said:
Yes, when it runs it nests the function under "Private Sub
cmdClearList_Click()" which causes the error. I placed the End Sub under
the
End Function, but it did not like that either.

Allen Browne said:
That should work. Are you getting an error message?

j1eggert said:
Allen:
I put the code in a module (Function to End Function) and then I put
the
=ClearList([lstFindRecords]) On Click property, but it is still not
working
when I push the Clear List command button. Do I need to do something in
the
command button to trigger the module I wrote? Here is what I wrote in
the
module:

Option Compare Database

Function ClearList(lst As ListBox)
Dim varItem As Variant

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


:

Save the function into a standard module.

Set the On Click property of your list box to:
=ClearList([List1])
where "List1" represents the name of your list box.

Function ClearList(lst As ListBox)
Dim varItem As Variant

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


I have set up a Find Records form for search the records listed in
the
table.
I have setup text boxes for searching the information with a Find
Records
command button. I have also set up a command button called "Clear
List".
What
I am wanting is to clear the records in the list box so I can do
another
search for a different set of records. If anyone can help with the
correct
syntax and procedures (example would be a great help) I would really
appreciate it.
 
Yes, I followed your previous instructions and created a module, pasted the
funciton in to it and in the On Click property in the List Box typed the
=ClearList([lstFindRecords]). But, when I click the Clear List command button
it does nothing. In addition, I notice that when I do add a record it
automatically puts it in the list box. The process is to put in text in the
text boxes and search the database for those particular items. Next, I will
set up a print button that will take lthe ist in the list box and print out a
report, then clear the list box to do additional searches. I hope this gives
you a little more information to make a better determination on what the
problem is. Do I need to set the Form's "On Current" field with the Macros
that has all the Query search parameters listed with the action "OpenQuery"
selected?

Allen Browne said:
The idea was to place the function in a standard module, so you can reuse it
for any list box on any form.

1. Click the Modules tab of the database window.
2. Click New. Access opens a new module.
3. Past the function in there.
4. Save the module with a name such as Module1.

Now set the On Click property to
=ClearList([lstFindRecords])

Or, if you want to set the On Click property to:
[Event Proceure]
then between the Private Sub... and End Sub lines, enter:
Call ClearList([lstFindRecords])

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

j1eggert said:
Yes, when it runs it nests the function under "Private Sub
cmdClearList_Click()" which causes the error. I placed the End Sub under
the
End Function, but it did not like that either.

Allen Browne said:
That should work. Are you getting an error message?

Allen:
I put the code in a module (Function to End Function) and then I put
the
=ClearList([lstFindRecords]) On Click property, but it is still not
working
when I push the Clear List command button. Do I need to do something in
the
command button to trigger the module I wrote? Here is what I wrote in
the
module:

Option Compare Database

Function ClearList(lst As ListBox)
Dim varItem As Variant

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


:

Save the function into a standard module.

Set the On Click property of your list box to:
=ClearList([List1])
where "List1" represents the name of your list box.

Function ClearList(lst As ListBox)
Dim varItem As Variant

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


I have set up a Find Records form for search the records listed in
the
table.
I have setup text boxes for searching the information with a Find
Records
command button. I have also set up a command button called "Clear
List".
What
I am wanting is to clear the records in the list box so I can do
another
search for a different set of records. If anyone can help with the
correct
syntax and procedures (example would be a great help) I would really
appreciate it.
 
Your original question (as I read it) was how to code to clear the items in
the list box.

If you select one or more items in the list box, and then click the button,
do they become unselected? That's what the code is designed to do.

If it does not do that, add this line to the top of the procedure, i.e. on a
new line just after "Function..."
Stop
Then when the code runs, if it is being called correctly, it will stop here,
and you can press F8 to step through the code and track down where the
problem is.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

j1eggert said:
Yes, I followed your previous instructions and created a module, pasted
the
funciton in to it and in the On Click property in the List Box typed the
=ClearList([lstFindRecords]). But, when I click the Clear List command
button
it does nothing. In addition, I notice that when I do add a record it
automatically puts it in the list box. The process is to put in text in
the
text boxes and search the database for those particular items. Next, I
will
set up a print button that will take lthe ist in the list box and print
out a
report, then clear the list box to do additional searches. I hope this
gives
you a little more information to make a better determination on what the
problem is. Do I need to set the Form's "On Current" field with the Macros
that has all the Query search parameters listed with the action
"OpenQuery"
selected?

Allen Browne said:
The idea was to place the function in a standard module, so you can reuse
it
for any list box on any form.

1. Click the Modules tab of the database window.
2. Click New. Access opens a new module.
3. Past the function in there.
4. Save the module with a name such as Module1.

Now set the On Click property to
=ClearList([lstFindRecords])

Or, if you want to set the On Click property to:
[Event Proceure]
then between the Private Sub... and End Sub lines, enter:
Call ClearList([lstFindRecords])


j1eggert said:
Yes, when it runs it nests the function under "Private Sub
cmdClearList_Click()" which causes the error. I placed the End Sub
under
the
End Function, but it did not like that either.

:

That should work. Are you getting an error message?

Allen:
I put the code in a module (Function to End Function) and then I put
the
=ClearList([lstFindRecords]) On Click property, but it is still not
working
when I push the Clear List command button. Do I need to do something
in
the
command button to trigger the module I wrote? Here is what I wrote
in
the
module:

Option Compare Database

Function ClearList(lst As ListBox)
Dim varItem As Variant

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


:

Save the function into a standard module.

Set the On Click property of your list box to:
=ClearList([List1])
where "List1" represents the name of your list box.

Function ClearList(lst As ListBox)
Dim varItem As Variant

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


I have set up a Find Records form for search the records listed in
the
table.
I have setup text boxes for searching the information with a Find
Records
command button. I have also set up a command button called "Clear
List".
What
I am wanting is to clear the records in the list box so I can do
another
search for a different set of records. If anyone can help with
the
correct
syntax and procedures (example would be a great help) I would
really
appreciate it.
 
Allen:
I tried highlighting the rows in the list box and press the Clear List
button. It removes the highlight, but not the information contained in the
fields. In addition, everytime I try to highlight a row I get this error
message "The expression On Click you entered as the event property setting
produced the following error. The epxression you entered has a function name
that Microsoft Office Access can't find."
Furthermore, I tried entering Stop on a new line under "Function
ClearList(lst As ListBox)" and under the "End Function" and it did not like
either one. Perhaps I am missunderstanding where to put the Stop in the code.
Really do appreciate your help.

Allen Browne said:
Your original question (as I read it) was how to code to clear the items in
the list box.

If you select one or more items in the list box, and then click the button,
do they become unselected? That's what the code is designed to do.

If it does not do that, add this line to the top of the procedure, i.e. on a
new line just after "Function..."
Stop
Then when the code runs, if it is being called correctly, it will stop here,
and you can press F8 to step through the code and track down where the
problem is.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

j1eggert said:
Yes, I followed your previous instructions and created a module, pasted
the
funciton in to it and in the On Click property in the List Box typed the
=ClearList([lstFindRecords]). But, when I click the Clear List command
button
it does nothing. In addition, I notice that when I do add a record it
automatically puts it in the list box. The process is to put in text in
the
text boxes and search the database for those particular items. Next, I
will
set up a print button that will take lthe ist in the list box and print
out a
report, then clear the list box to do additional searches. I hope this
gives
you a little more information to make a better determination on what the
problem is. Do I need to set the Form's "On Current" field with the Macros
that has all the Query search parameters listed with the action
"OpenQuery"
selected?

Allen Browne said:
The idea was to place the function in a standard module, so you can reuse
it
for any list box on any form.

1. Click the Modules tab of the database window.
2. Click New. Access opens a new module.
3. Past the function in there.
4. Save the module with a name such as Module1.

Now set the On Click property to
=ClearList([lstFindRecords])

Or, if you want to set the On Click property to:
[Event Proceure]
then between the Private Sub... and End Sub lines, enter:
Call ClearList([lstFindRecords])


Yes, when it runs it nests the function under "Private Sub
cmdClearList_Click()" which causes the error. I placed the End Sub
under
the
End Function, but it did not like that either.

:

That should work. Are you getting an error message?

Allen:
I put the code in a module (Function to End Function) and then I put
the
=ClearList([lstFindRecords]) On Click property, but it is still not
working
when I push the Clear List command button. Do I need to do something
in
the
command button to trigger the module I wrote? Here is what I wrote
in
the
module:

Option Compare Database

Function ClearList(lst As ListBox)
Dim varItem As Variant

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


:

Save the function into a standard module.

Set the On Click property of your list box to:
=ClearList([List1])
where "List1" represents the name of your list box.

Function ClearList(lst As ListBox)
Dim varItem As Variant

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


I have set up a Find Records form for search the records listed in
the
table.
I have setup text boxes for searching the information with a Find
Records
command button. I have also set up a command button called "Clear
List".
What
I am wanting is to clear the records in the list box so I can do
another
search for a different set of records. If anyone can help with
the
correct
syntax and procedures (example would be a great help) I would
really
appreciate it.
 
So the code does unhighlight the items in the list (that's its intent), but
you actually want to remove the items from the list?

The answer to that question will depend where the list gets its items from,
and how you want them removed.

If the list gets its items from a table, you could delete all the items from
the table (e.g. execute a DELETE query), and then Requery the list box.

If you don't want to delete the items from the table - just not show them -
then change the RowSource of the list box to something like this:
SELECT * FROM Table1 WHERE (False);

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

j1eggert said:
Allen:
I tried highlighting the rows in the list box and press the Clear List
button. It removes the highlight, but not the information contained in the
fields. In addition, everytime I try to highlight a row I get this error
message "The expression On Click you entered as the event property setting
produced the following error. The epxression you entered has a function
name
that Microsoft Office Access can't find."
Furthermore, I tried entering Stop on a new line under "Function
ClearList(lst As ListBox)" and under the "End Function" and it did not
like
either one. Perhaps I am missunderstanding where to put the Stop in the
code.
Really do appreciate your help.

Allen Browne said:
Your original question (as I read it) was how to code to clear the items
in
the list box.

If you select one or more items in the list box, and then click the
button,
do they become unselected? That's what the code is designed to do.

If it does not do that, add this line to the top of the procedure, i.e.
on a
new line just after "Function..."
Stop
Then when the code runs, if it is being called correctly, it will stop
here,
and you can press F8 to step through the code and track down where the
problem is.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

j1eggert said:
Yes, I followed your previous instructions and created a module, pasted
the
funciton in to it and in the On Click property in the List Box typed
the
=ClearList([lstFindRecords]). But, when I click the Clear List command
button
it does nothing. In addition, I notice that when I do add a record it
automatically puts it in the list box. The process is to put in text in
the
text boxes and search the database for those particular items. Next, I
will
set up a print button that will take lthe ist in the list box and print
out a
report, then clear the list box to do additional searches. I hope this
gives
you a little more information to make a better determination on what
the
problem is. Do I need to set the Form's "On Current" field with the
Macros
that has all the Query search parameters listed with the action
"OpenQuery"
selected?

:

The idea was to place the function in a standard module, so you can
reuse
it
for any list box on any form.

1. Click the Modules tab of the database window.
2. Click New. Access opens a new module.
3. Past the function in there.
4. Save the module with a name such as Module1.

Now set the On Click property to
=ClearList([lstFindRecords])

Or, if you want to set the On Click property to:
[Event Proceure]
then between the Private Sub... and End Sub lines, enter:
Call ClearList([lstFindRecords])


Yes, when it runs it nests the function under "Private Sub
cmdClearList_Click()" which causes the error. I placed the End Sub
under
the
End Function, but it did not like that either.

:

That should work. Are you getting an error message?

Allen:
I put the code in a module (Function to End Function) and then I
put
the
=ClearList([lstFindRecords]) On Click property, but it is still
not
working
when I push the Clear List command button. Do I need to do
something
in
the
command button to trigger the module I wrote? Here is what I
wrote
in
the
module:

Option Compare Database

Function ClearList(lst As ListBox)
Dim varItem As Variant

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


:

Save the function into a standard module.

Set the On Click property of your list box to:
=ClearList([List1])
where "List1" represents the name of your list box.

Function ClearList(lst As ListBox)
Dim varItem As Variant

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


I have set up a Find Records form for search the records listed
in
the
table.
I have setup text boxes for searching the information with a
Find
Records
command button. I have also set up a command button called
"Clear
List".
What
I am wanting is to clear the records in the list box so I can
do
another
search for a different set of records. If anyone can help with
the
correct
syntax and procedures (example would be a great help) I would
really
appreciate it.
 
Thanks, I think this is going to work fine. After entering the code ti
immediately cleared the columns in the list box. I would like to test it out
further; however, I need to set the Find Records button working so it will
pull the information from the table to the list box based on the criteria
entered in the text boxes. What do you recommend to accomplish the Find
Record function?

Allen Browne said:
So the code does unhighlight the items in the list (that's its intent), but
you actually want to remove the items from the list?

The answer to that question will depend where the list gets its items from,
and how you want them removed.

If the list gets its items from a table, you could delete all the items from
the table (e.g. execute a DELETE query), and then Requery the list box.

If you don't want to delete the items from the table - just not show them -
then change the RowSource of the list box to something like this:
SELECT * FROM Table1 WHERE (False);

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

j1eggert said:
Allen:
I tried highlighting the rows in the list box and press the Clear List
button. It removes the highlight, but not the information contained in the
fields. In addition, everytime I try to highlight a row I get this error
message "The expression On Click you entered as the event property setting
produced the following error. The epxression you entered has a function
name
that Microsoft Office Access can't find."
Furthermore, I tried entering Stop on a new line under "Function
ClearList(lst As ListBox)" and under the "End Function" and it did not
like
either one. Perhaps I am missunderstanding where to put the Stop in the
code.
Really do appreciate your help.

Allen Browne said:
Your original question (as I read it) was how to code to clear the items
in
the list box.

If you select one or more items in the list box, and then click the
button,
do they become unselected? That's what the code is designed to do.

If it does not do that, add this line to the top of the procedure, i.e.
on a
new line just after "Function..."
Stop
Then when the code runs, if it is being called correctly, it will stop
here,
and you can press F8 to step through the code and track down where the
problem is.

--
Allen Browne - Microsoft MVP. Perth, Western Australia.

Reply to group, rather than allenbrowne at mvps dot org.

Yes, I followed your previous instructions and created a module, pasted
the
funciton in to it and in the On Click property in the List Box typed
the
=ClearList([lstFindRecords]). But, when I click the Clear List command
button
it does nothing. In addition, I notice that when I do add a record it
automatically puts it in the list box. The process is to put in text in
the
text boxes and search the database for those particular items. Next, I
will
set up a print button that will take lthe ist in the list box and print
out a
report, then clear the list box to do additional searches. I hope this
gives
you a little more information to make a better determination on what
the
problem is. Do I need to set the Form's "On Current" field with the
Macros
that has all the Query search parameters listed with the action
"OpenQuery"
selected?

:

The idea was to place the function in a standard module, so you can
reuse
it
for any list box on any form.

1. Click the Modules tab of the database window.
2. Click New. Access opens a new module.
3. Past the function in there.
4. Save the module with a name such as Module1.

Now set the On Click property to
=ClearList([lstFindRecords])

Or, if you want to set the On Click property to:
[Event Proceure]
then between the Private Sub... and End Sub lines, enter:
Call ClearList([lstFindRecords])


Yes, when it runs it nests the function under "Private Sub
cmdClearList_Click()" which causes the error. I placed the End Sub
under
the
End Function, but it did not like that either.

:

That should work. Are you getting an error message?

Allen:
I put the code in a module (Function to End Function) and then I
put
the
=ClearList([lstFindRecords]) On Click property, but it is still
not
working
when I push the Clear List command button. Do I need to do
something
in
the
command button to trigger the module I wrote? Here is what I
wrote
in
the
module:

Option Compare Database

Function ClearList(lst As ListBox)
Dim varItem As Variant

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


:

Save the function into a standard module.

Set the On Click property of your list box to:
=ClearList([List1])
where "List1" represents the name of your list box.

Function ClearList(lst As ListBox)
Dim varItem As Variant

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


I have set up a Find Records form for search the records listed
in
the
table.
I have setup text boxes for searching the information with a
Find
Records
command button. I have also set up a command button called
"Clear
List".
What
I am wanting is to clear the records in the list box so I can
do
another
search for a different set of records. If anyone can help with
the
correct
syntax and procedures (example would be a great help) I would
really
appreciate it.
 
If it is a multi-select list box, you will need to loop through the
ItemsSelected property to build up the string to use for the Filter of your
form. You could adapt the code from this article so the string ends up as
the Filter of the form instead of the WhereCondition of the OpenReport:
Use a multi-select list box to filter a report
at:
http://allenbrowne.com/ser-50.html

If it is a single-select list box, and there is only one matching item in
your form, adapt this example:
Using a Combo Box to Find Records
at:
http://allenbrowne.com/ser-03.html
 
Allen:
I followed the instructions and one of the code statements toward the end
came up with an error and highlighted the Err_Handler: MsgBox. Furthermore, I
don't know how this helps my situation since I tried the form and it does not
work.
 
Allen:
Thank you for your help and I understand you cannot allow someone to
dominate your time. Have a great day.
 
How to I change this to make it work for a combo box?

I pasted the code into a module and tried to use it to clear a combo box.

Since it was a data mismatch error I changed it to a list box. The fucntion
worked.

I'd like to use this for a form that has multiple combo boxes. I tried
changing the first line to

Function ClearList(lst As ComboBox)

but then when I compiled I recieved the error message:

"compile error: Method or data member not found"
for .Multiselect in the opening if line.


I tried deleting the multiselect portion but then have the same error for
ItemsSelected.
 
Only one item at a time can ever be selected in a combo box, so there isn't
any list to clear.

To clear a combo box selection, just set the value of the combo box to Null
....

Me.NameOfComboBox = Null
 
Thanks.



Brendan Reynolds said:
Only one item at a time can ever be selected in a combo box, so there isn't
any list to clear.

To clear a combo box selection, just set the value of the combo box to Null
....

Me.NameOfComboBox = Null
 
Back
Top