473,395 Members | 1,386 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

how to pass listbox as function parameter

I need to clear selections from several listboxes at the same time.
Using Allen Browne's code shown below,
how do I pass by variable (rather than one specific listbox name) so that I can clear all selections for Listbox List0 through List7 at the same time?

I have tried

Expand|Select|Wrap|Line Numbers
  1. Dim i As Integer
  2. Dim strListBox As String
  3.  
  4. For i=0 to 7
  5.   strListBox = "List" & i
  6.   call ClearList(Me.Controls.Item(strListBox))]
  7. Next i
  8.  
This does not work.
Please HELP!!! Thank you in advance.

Allen Browne's code:
Expand|Select|Wrap|Line Numbers
  1. To deselect them all:
  2.     Call ClearList(Forms!Form1!List0)
  3. --------------------------------------------------------------------------------
  4.  
  5. Function ClearList(lst As ListBox) As Boolean
  6. On Error GoTo Err_ClearList
  7.     'Purpose:   Unselect all items in the listbox.
  8.     'Return:    True if successful
  9.     'Author:    Allen Browne. http://allenbrowne.com  June, 2006.
  10.     Dim varItem As Variant
  11.  
  12.     If lst.MultiSelect = 0 Then
  13.         lst = Null
  14.     Else
  15.         For Each varItem In lst.ItemsSelected
  16.             lst.Selected(varItem) = False
  17.         Next
  18.     End If
  19.  
  20.     ClearList = True
  21.  
  22. Exit_ClearList:
  23.     Exit Function
  24.  
  25. Err_ClearList:
  26.     Call LogError(Err.Number, Err.Description, "ClearList()")
  27.     Resume Exit_ClearList
  28. End Function
May 19 '10 #1
3 8534
NeoPa
32,556 Expert Mod 16PB
"This does not work" is very little to go on.

please post where the problem occurred and an error message. With that we can attempt to help.

Welcome to Bytes!
May 19 '10 #2
NeoPa:

Thank you for the warm welcome. I know I should have been more specific.
Actually, came back to say the code is working now. When copying over Allen Browne's code, I needed to take out the part checking for .multiselect and accidentally removed the For Loop "For Each varItem In lst.ItemsSelected" as well. Silly me. After the lines are put back in, the code works perfectly well.
May 19 '10 #3
NeoPa
32,556 Expert Mod 16PB
Thanks for letting us know.

I'm afraid that doesn't qualify as a best answer though. For that we would need a question with an identifiable problem.

I'm pleased you're all sorted out anyway :)
May 19 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: pablo | last post by:
Dear Newsgroupers, The 'main' page contains a call to a function in an included file. This function puts a html-form on the screen. Before the form gets posted (to the 'main' page) some prior...
5
by: John T | last post by:
I am trying to make a function that takes an optional parameter that gets passed by reference. Here is the first line of my function definition: function funQueryDatabase($strQuery,...
3
by: Paul T. Rong | last post by:
I have a listbox (of product names) control on my form. I want to pass the selected item (a product name) to a subform, and the product unitprice should apear automatically next to the product name...
5
by: Rolf Wester | last post by:
Hi, I want to pass a C-function as a function parameter but I don't know how to that correctly. In the example below how would I have to declare the function argument in the my_sort function...
2
by: Matthew Louden | last post by:
When I pass an array as a function parameter, it yields the following compile error. Any ideas?? However, if I create a variable that holds an array, and pass that variable to the function...
2
by: Glenn Lerner | last post by:
If I pass a reference type (such as DataSet) to a function, I'm assuming only a reference is passed (not a copy). So there is no need to declare function parameter as ref for those types? Example:...
16
by: hzmonte | last post by:
Correct me if I am wrong, declaring formal parameters of functions as const, if they should not be/is not changed, has 2 benefits; 1. It tells the program that calls this function that the...
3
by: giloosh | last post by:
can i pass a hash as a function parameter. ive seen it been used before but i can't figure out how to do it. i would like to call a function like this for example ...
6
by: =?Utf-8?B?emlubw==?= | last post by:
I'm trying to pass a delegate as parameter but the code below does not compile. It display an error: 'AddressOf operand must the name of a method(without parantheses)' How can I make it work. ...
1
by: Eva | last post by:
I need to pass listbox selected values to crystal report from .net 2005.when I am doing it the error display "The types of the parameter field and parameter field current values are not compatible."...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.