Unanswered: Referencing forms in an external Project
Ok, my google-fu is weak, so I could use a hint :-)
I have an .ade (let's call it main.ade) with a lot of forms and reports. I want to move the reports and some of the forms to a separate .adp (let's call that components.adp) in order to make them editable on-site. I've played around with references and I can call main.ade code from components.ade (that's necessary). But I can't figure out how to access the reports and forms in components.adp from main.ade.
Depending on how I set references, I can open the form/report from VBA-project explorer, but not from code. Any hints would be greatly appreciated.
I would think you need a reference to the Access Application that has the other database open (main.ade). It would be like controlling what is happening inside of Access from either Word or Excel VBA. Then you would be able to reference the Forms collection of the Appliction object. This is a guess and suggestion. I have not tried it, but it sounds like it has a chance of working.
Well, I can open the forms in component.adp through a new access.aplication object. But that opens the form in a new access window (or an OLE container) which is not exactly what I want (besides, it takes up a lot of resources).
I was more thinking along the lines of a "form repository", which works quite like a DLL or an ADE with code that you can reference.
The only way I can think to do that would be to use it as a place to copy the form from and into the current database for use. But as a place to open the form from and use, I don't think that is going to happen. But if you find a way, I would love to hear about it. I also think it is a great idea. It would be nice to have a lot of standard forms in one place and then use them whenever needed.
public function createComponentForm(formname as string) as Access.Form
select case formname
set createComponentform = New Form_MyForm
With a reference to components.adp, I can call
set frm = createComponentForm("myForm")
frm.visible = true
and voila, the form is there, without creating another instance of access. Expressions like forms!frmMain!txtFoo on myForm work as well with frmMain being in main.ade. The only thing I can't figure out is how to display frm as a subform.
subform.SourceObject = frm.name
doesn't work :-( though frm.name returns the correct name. And of course, subform.form is read-only.
What you are creating with the function is an instance of a form as an object, which is different from what we have within one database when we "open" a form and it is opened. At that point it is in the Forms collection. Is your form that you "create" with the function in the forms collection? I'm assuming it is not. When you want to use this new form "frm" as a sub form, I'm assuming it is as a form within another form, (I know, stick with me here) rather than a sub-form to a main form (Orders and order details). So, as a subform, there would be no tie to the parent, as there would be in a Master/Child with link fields. IF, and a big IF, this is the case, I would think you could make it look like a subform by placing it, with no controlbox, close button, minimize/maximize buttons. Of course, your "main" form could not be moved either.
You are right, it is not in the forms collection. Your suggestion (placing the form at the right spot) would work, but I'd rather avoid "floating" forms as weird things tend to happen with the positioning.
I'm thinking of writing an activeX container object that displays an access.form object. I'm quite determined to get that working somehow because it would make my life a lot easier afterwards ;-).
Oh, and yes, I can live without linked fields. All filtering is done in SQL, anyway, and input parameters do already work with that new frm object.