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.