ms access - How to write generic code to open a form by instantiating the underlying class associated with the form -


i think classed advanced access question.

i trying write generic code open form instantiating underlying class associated form. don't know type use when passing "form class" in parameter.

i think "mocked example" code below explains question better :

option compare database option explicit  sub openallmyforms()      ' have 3 access forms named myformname1, myformname2 , myformname3     ' use code open 3 of them      form_open_myformname1     ' form_open_myformname2     ' in example have not included procedure used open myformname2 , myformname3     ' form_open_myformname3  end sub  function form_open_myformname1() form      '     ' current code  (each form gets opened has function this)     '      dim frm form      set frm = new form_myformname1      ' note form_ significant.     ' form name in access navigation pane shown "myformname1"     ' preceeding name "form_" causes underlying class returned     ' implements access "form" class.  (i think how in oo speak)       ' add form collection, lets not complicate example     ' clnofforms_myformname1.add item:=frm, key:=cstr(frm.hwnd)      set form_open_myformname1 = frm      frm.visible = true      set frm = nothing  end function   sub openallmyformsnew()     '     ' want write generic function open form     ' replace sub openallmyforms (ie above) sub.     ' no longer have "form_open_myformname1" function each form     ' instead use form_open - see below.      dim frm1 form     dim frm2 form     dim frm3 form      '     ' note form_ significant.     ' form name in access navigation pane shown "myformname1"     ' preceeding name "form_" causes underlying class returned     '     set frm1 = form_open(aform:=form_myformname1)     set frm2 = form_open(aform:=form_myformname2)     set frm3 = form_open(aform:=form_myformname3)  end sub  function form_open(aformclass whattypeshouldiusehere) form      '     ' here new function, don't know how work.     ' don't know type use parameter aformclass see "whattypeshouldiusehere" above.     '      dim frm form      set frm = new aformclass      set form_open = frm      set frm = nothing  end function 

the form class itself.

but don't spend time on this. access uses objects , classes not oop. if strive fancy programming, vba not you.

you can reach point using withevents. little documentation on topic, blog should started:

browse little history

problem is, when drive technique too far, access crashes. , don't expect corrected; ms consider not access developer environment, rather tool superusers , sharepoint.

so visual studio honour efforts , not waste time.


Comments