View Single Post
 
Old 01-29-2018, 12:19 PM
Cosmo Cosmo is offline Windows Vista Office 2007
Competent Performer
 
Join Date: Mar 2012
Posts: 240
Cosmo is on a distinguished road
Default Show userForm from variable

I have several documents which use the same userForms, and I'm trying to make a function to show them in a specific order (Not all will contain the same forms, not always the same order). I have created an array with the forms in the order they need, but I can't seem to use the contents of the array to show the forms. I can use the TypeName and a Select Case block to show the form, but since not all documents will have all of the forms, this won't compile across the board. Plus, if I need to add/delete/rename any of the userforms, it will require updating this section, which I would prefer not to be hard-coded.

Code:
    ' Create an array using the needed forms in order:
    Dim dialogs(4) As UserForm
 
    ' NOTE: Using 'NEW' doesn't make any difference to functionality
    Set dialogs(0) = frmDataInput
    Set dialogs(1) = frmSummaryInput
    Set dialogs(2) = New frmCondition
    Set dialogs(3) = New frmSummaryInput
 
    ' The following code would be in a separate function, common to all documents
    Dim i As Integer
    Dim ct As Integer
 
    ct = UBound(dialogs)
    For i = 0 To ct
        Set dialog = dialogs(i)
 
        ' NOTE: This doesn't work:
        ' dialog.show
 
        ' Need to use 'Select Case' to activate forms
        Dim name As String
        name = TypeName(dialog)
        Select Case name
        Case "frmSummaryInput"
            frmSummaryInput.show
        Case "frmDataInput"
            frmDataInput.show
        Case "frmCondition"
            frmCondition.show
        End Select
 
    Next I
Is there a way to get the 'dialog' variable to run it's 'show' method without needing to hard-code all of the form names?
Reply With Quote