Consulting

Results 1 to 4 of 4

Thread: List Box - Reset Button - Search Filter Clear

  1. #1
    VBAX Mentor
    Joined
    Feb 2016
    Location
    I have lived in many places, I love to Travel
    Posts
    413
    Location

    List Box - Reset Button - Search Filter Clear

    hi folks,

    i am having listbox problems.

    i am not sure what i have done wrong on my list box reset , the reset button doesnt work any more.

    I search for items and then i would like to reset back to original search - well I'm not sure i can do it justice explaining it so I atatched my book

    please take a look

    thank you
    Attached Files Attached Files
    Cheers for your help

    dj

    'Extreme VBA Newbie in progress - one step at a time - like a tortoise's pace'


  2. #2
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    Try moving the Dim of arrList to the module level, instead of inside UserForm_Initialize



    Dim arrList(6, 4)                    ' <<<<<<<<<<<<<<<<<<<<<<< Rows , Columns in Array
            
    Private Sub cmdResetList_Click()
        Me.ListBox100.List = arrList
        Me.TextBox1 = vbNullString
    End Sub
    
    
    
    
    
    
     
    Private Sub UserForm_Initialize()
        
        Dim I
     
        ListBox100.ColumnCount = 4
        
        '---- Listbox Index Numbers
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

  3. #3
    VBAX Mentor
    Joined
    Feb 2016
    Location
    I have lived in many places, I love to Travel
    Posts
    413
    Location
    Thanks Paul,


    I’ve been at it again butchering my code thanks to misinformation - and I’ve scoured the net to no avail

    I just don’t have the wisdom to know where to put these things -
    in the Microsoft web page where i got my array from they put it exactly where I put it

    Oh well after 3 hours of stress, I better get me self a cuppa and one for you too

    Thanks for that

    Cheers for your help

    dj

    'Extreme VBA Newbie in progress - one step at a time - like a tortoise's pace'


  4. #4
    VBAX Sage
    Joined
    Apr 2007
    Location
    United States
    Posts
    8,724
    Location
    Quote Originally Posted by dj44 View Post
    Thanks Paul,
    I just don’t have the wisdom to know where to put these things -
    in the Microsoft web page where i got my array from they put it exactly where I put it
    I suspect that in the MS web page, the variable arrList scoped only to the sub UserForm_Initialize (i.e. only used in)

    When you added cmdResetList_Click, arrList was invisible (i.e. out of scope) to your sub

    By moving the Dim to outside of any procedure (i.e. module level) is was now in scope for subs and functions IN THAT MODULE

    Using Public arrList () .... would make it in scope for ALL MODULES


    Night time reading ...


    https://support.microsoft.com/en-us/...r-applications

    http://www.cpearson.com/excel/scope.aspx


    Be advised that if you had Dim arrList in Userform_Initialize and Dim arrList at the module level, within the UF_Init sub, it's arrList would be used, but every one else would use the module's arrList

    Gets messy, and I never have the same name on different scoped variables
    ---------------------------------------------------------------------------------------------------------------------

    Paul


    Remember: Tell us WHAT you want to do, not HOW you think you want to do it

    1. Use [CODE] ....[/CODE ] Tags for readability
    [CODE]PasteYourCodeHere[/CODE ] -- (or paste your code, select it, click [#] button)
    2. Upload an example
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) / Upload Files / Done
    3. Mark the thread as [Solved] when you have an answer
    Thread Tools (on the top right corner, above the first message)
    4. Read the Forum FAQ, especially the part about cross-posting in other forums
    http://www.vbaexpress.com/forum/faq...._new_faq_item3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •