1

In MS Access, there are two ways to open a new form:

  1. DoCmd.OpenForm "myForm" - opens the "default instance" of a form

  2. Set frm = New Form_myForm : frm.Visible = True - opens a new instance of a form.

I need to use the second option, because I want to open multiple instances of myForm. (If you are unfamiliar with it, more details about this technique can be found here.)

How would I do that if I have the name of the form only available as a string? I.e., I need to write some library method

Sub OpenAnotherInstanceOfForm(ByVal formName As String)
    Dim frm As Form ' or Object, late binding is fine for me in this case

    Set frm = ... ' <-- What goes here?
    frm.Visible = True

    ... ' Persist the object reference, so that frm stays open. I know how to do that.
End Sub

Here is what I have already tried:

  • Set frm = CreateObject("Form_" & formName) - Run time error 429
  • Set frm = Eval("New Form_" & formName) - Run time error 2482
braX
  • 11,506
  • 5
  • 20
  • 33
Heinzi
  • 167,459
  • 57
  • 363
  • 519

0 Answers0