+ Reply to Thread
Results 1 to 6 of 6

A re-usable Form with a listbox filled with an array defined when .SHOW - how to define?

  1. #1
    Registered User
    Join Date
    08-15-2013
    Location
    London
    MS-Off Ver
    Multiple versions
    Posts
    27

    Question A re-usable Form with a listbox filled with an array defined when .SHOW - how to define?

    Hi. Hope someone can help a VB-dabbler get past this issue.

    I want to create a Form that I can re-use multiple times within a main macro. The idea is that the form presents a set of options that can be multi-chosen, writes that back to a cell, then next time it is invoked presents a different set of options (and writes that response back to a different cell).

    It's on changing the options that I'm getting stuck.


    My test sheet has two defined ranges, "VideoCheck" and "AudioCheck" containing my data, and my form has a list box "lstWhatColumns" that provides the picking choice. I've created the form ("frmWhatColumns") and sorted the write-back, but the only way I can set the RowSource so that it works is to explicitly define the Range in the RowSource property of the listbox itself.

    My (very crude) test code is as follows:
    Please Login or Register  to view this content.
    So long as the RowSource is explicitly defined with a Range name this works fine, but what I want to be able to do is - within the main macro - be able to pass the RowSource in to the list box at the point of calling.

    I have been experimenting with frmWhatColumns.lstWhatColumns.RowSource = VideoChecks - but I cannot find where this needs to sit so that it sets the data.

    Any assistance greatly appreciated.

    Kind regards

    Steve

  2. #2
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: A re-usable Form with a listbox filled with an array defined when .SHOW - how to defin

    I'd do it like this - I don't like rowsource, it's a bit faffy:
    Please Login or Register  to view this content.
    Then - userform:
    Please Login or Register  to view this content.
    Last edited by Kyle123; 08-16-2013 at 06:50 AM.

  3. #3
    Registered User
    Join Date
    08-15-2013
    Location
    London
    MS-Off Ver
    Multiple versions
    Posts
    27

    Re: A re-usable Form with a listbox filled with an array defined when .SHOW - how to defin

    Hi Kyle

    That, sir, is a thing of beauty! Addresses my problem exactly.

    I can progress with my experiments now. They have drawn up another issue, but as I spent ages trawling rather full threads to try and find this one little nugget of info I am going to post it separately, so that I can leave this as a self-contained response to one thing.

    Many thanks once again.

    Kind regards

    Steve

  4. #4
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: A re-usable Form with a listbox filled with an array defined when .SHOW - how to defin

    Glad it helped

  5. #5
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643
    Kyle

    Just curious, why the Property Get/Let stuff?

    Is there any advantage over setting List and returning the selected items in the usual way?
    If posting code please use code tags, see here.

  6. #6
    Forum Guru Kyle123's Avatar
    Join Date
    03-10-2010
    Location
    Leeds
    MS-Off Ver
    365 Win 11
    Posts
    7,238

    Re: A re-usable Form with a listbox filled with an array defined when .SHOW - how to defin

    Hi Norie, it's largely sticking to convention and personal preference.

    My coding (probably due to me working in C# and javascript most of the time) tends to be fairly object orientated, as such I tend to encapsulate process in the class it is in and I'll always prefer to interact with properties of that class than variables directly. As such I would (in the round) consider objects (controls etc) within a useform private and interact only with exposed properties/explicit public routines - If I'm feeling really pedantic I might even go as fas as to make an interface class for the userform

    I also don't use global variables if I can help it, the usual userform falls firmly into this category in my opinion, I'd rather narrow the scope of the user form and have full control over its initialization and removal, this also allows me to have multiple instances of it open at once. Since I try to stick to a single convention for doing something so any code is consistent, I only ever initialize userforms in this manner, I always declare a new instance of them - it also allows me to check if they're nothing which can be handy in certain circumstances.

    Pedantic Version of the above :
    Please Login or Register  to view this content.
    Form:
    Please Login or Register  to view this content.
    Interface:
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Define Array from Listbox to enable ExportAsFixedFormat
    By superdonk in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-28-2013, 01:05 PM
  2. [SOLVED] if Row A contains text, SUM all filled in from row A, and show number of filled in in A150
    By jeroenheki in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 10-12-2012, 06:23 AM
  3. how to show (time) of cells to the listbox of a form
    By chinrose in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-14-2011, 04:17 AM
  4. Blank lines in array filled listbox
    By macquarl in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-08-2008, 12:42 PM
  5. [SOLVED] Passing User Defined Type Array to Listbox
    By PC in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-31-2005, 10:05 PM

Tags for this Thread

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1