Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 01-29-2018, 12:19 PM
Cosmo Cosmo is offline Show userForm from variable Windows Vista Show userForm from variable Office 2007
Competent Performer
Show userForm from variable
 
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
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Show userForm from variable Assigning a string variable to a userform label caption Larry_1 Excel Programming 3 12-18-2017 06:59 AM
Show userForm from variable Show Userform when Content Control CheckBox ticked derajlance Word VBA 1 05-13-2016 01:55 PM
Using Userform.Show in Excel 2013 BillCPA Excel Programming 0 05-04-2015 09:52 AM
Command button to show userform suddenly stopped working jpb103 Word VBA 0 05-22-2014 06:05 AM
Show userForm from variable Show userform without losing document focus? Or other method to get a graphic to pop? AlexR Word VBA 7 03-31-2013 12:17 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:15 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft