0

I am trying to create a function which delete all the Items listed in a ListBox. However, when I Try to pass the name of the ListBox, it returns an error: Inavlid Parameters.

Here is the code:

Public Function CleanList(ListName As ListBox)
Dim intItemsInList As Integer
Dim intCounter As Integer

intItemsInList = ListName.ListCount

For intCounter = 0 To intItemsInList - 1
    ListName.RemoveItem 0
Next

End Function

Here is how I am calling the function:

Call CleanList(List_List1.Name)

The name of the ListBox I am using is List_List1

If I don't type the Method .Name, it shows the first Item of the List. I have tried without the Parentheses, without success.

Could you help me?

Thanks and Regards!

1 Answer 1

1

Your function doesn't accept a string (listbox name), but a Listbox object.

Which is the best way for a function like that.

So when calling the function, you only pass the object, not its name:

Call CleanList(Me!List_List1)
Sign up to request clarification or add additional context in comments.

2 Comments

It worked! Thanks! But if I want to use the ".Name", I have changed the function to an String. However, when the other method inside the function ".ListCount" is running I get an error for "Invalid Qualifier". How I am suppose to solve this? Thanks Again
Again, it is best to pass the object, not the name. To resolve the name, you would need to pass the form as well, but that makes no sense. Call CleanList(Me, "List_List1")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.