How to create a new form instance using the name of the form as a String

后端 未结 3 476
遥遥无期
遥遥无期 2021-01-24 23:46

Code to create new form instance of a closed form using form name

I want to replace the long Select Case list with a variable.

Full code of modu

3条回答
  •  甜味超标
    2021-01-25 00:15

    I think you are looking for something like this MS-Access 2010 function. (The GetForm sub is just for testing):

    Function SelectForm(ByVal FormName As String, ByRef FormExists As Boolean) As Form
        For Each f In Application.Forms
          If f.Name = FormName Then
            Set SelectForm = f
            FormExists = True
            Exit Function
          End If
        Next
        FormExists = False
    End Function
    
    Sub GetForm(ByVal FormName As String)
    
      Dim f As New Form
      Dim FormExists As Boolean
      Set f = SelectForm(FormName, FormExists)
      If FormExists Then
        MsgBox ("Form Found: " & f.Caption) 
      Else
        MsgBox ("Form '" & FormName & "' not found.")
      End If
    
    End Sub
    

提交回复
热议问题