Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VBA Listbox - Multi_section(1) - Default to ALL items checked? 1

Status
Not open for further replies.

Welshbird

IS-IT--Management
Jul 14, 2000
7,378
DE
Hi all,

I know that in this case I can't use the VALUE property of the listbox, and I have tried to use the code I would have used for the 'ALL' button I have on my form on a USERFORM_OPEN() sub, but that doesn't seem to work.

Sadly, neither will it work in the module that opens the form when the button is clicked.

Any ideas?

The code I use to select all when the 'ALL' button is pressed follows:
Code:
Private Sub ProdAll_Click()
' Select all from list box
    Dim r As Integer
    For r = 0 To ProdList.ListCount - 1
        ProdList.Selected(r) = True
    Next r
End Sub

Fee

"The cure for anything is salt water – sweat, tears, or the sea." Isak Dinesen
 


Hi,

Works for me.

Created a Multi Select(1) listbox names ProdList.

Ran your code unaltered.

Just as an aside: I would not name that procedure as ...Click, because it has nothing to do with an event. It's just a procedure that you call from the UserForm_Activate event. I'd call it ProdAll
Code:
Private Sub UserForm_Activate()
    ProdAll
End Sub
Private Sub ProdAll()
' Select all from list box
    Dim r As Integer
    For r = 0 To ProdList.ListCount - 1
        ProdList.Selected(r) = True
    Next r
End Sub


Skip,

[glasses]Just traded in my old subtlety...
for a NUANCE![tongue]
 
ARG! I was trying to call it from a USERFORM_OPEN() not a USERFORM_ACTIVATE().

Thanks again Skip.

(still learning!)

Fee

"The cure for anything is salt water – sweat, tears, or the sea." Isak Dinesen
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top