Refer to form object module by variable

Galaxiom

Super Moderator
Staff member
Local time
Today, 19:15
Joined
Jan 20, 2009
Messages
12,834
An instance of a form can be opened with:

Dim frm As Form
Set frm = New Form_formname

How can this be done using a variable as the formname?
 
Not tested, but how about..
Code:
Dim frm As Form
Set frm = New Forms(frmVar)
 
Thanks Paul but on further investigation today it seems that it can't be done. Bottom line is that Types cannot be variables.

The only workaround is to have a case statement to direct which one of a specific list of forms is to provide the object model. Defeats any idea of a generic object capable of creating an instance of an object without hard coding that particular pesky line.

Set frm = Form_formname
 
Well that is a shame ! Well I am glad we both learned something new this year ! :D
 
I don't know if it fulfilled your requirement, if you want to set "frm" to a form there isn't open, you can open the form hidden.

Code:
  Dim frm As New Form, FormName As String
  
  FormName = "AFormName"
  DoCmd.OpenForm FormName, acNormal, , , , acHidden
  Set frm = Forms(FormName)
  'DoCmd.Close acForm, dd, acSaveNo
 
Defeats any idea of a generic object capable of creating an instance of an object without hard coding that particular pesky line.

Set frm = Form_formname

And I suppose the environment that Application.Eval() creates is not suitable to to succeed at making the LOC generic? Did you try?
 

Users who are viewing this thread

Back
Top Bottom