Results 1 to 10 of 10
  1. #1
    Join Date
    Mar 2002
    Location
    Bielefeld, Germany
    Posts
    69

    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.

  2. #2
    Join Date
    Apr 2006
    Posts
    157
    not really the easiest solution but you may try APIs
    get the handle for the window/form...
    Only quitters quit!

  3. #3
    Join Date
    Jan 2007
    Location
    California, USA
    Posts
    520
    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.

  4. #4
    Join Date
    Mar 2002
    Location
    Bielefeld, Germany
    Posts
    69
    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.

  5. #5
    Join Date
    Jan 2007
    Location
    California, USA
    Posts
    520
    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.

  6. #6
    Join Date
    Mar 2002
    Location
    Bielefeld, Germany
    Posts
    69
    This is how far I got:
    in components.adp, I added

    public function createComponentForm(formname as string) as Access.Form
    select case formname
    case "myForm"
    set createComponentform = New Form_MyForm
    case ...
    End Select
    End Function

    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.
    Last edited by chrisp_999; 02-20-07 at 12:10.

  7. #7
    Join Date
    Jan 2007
    Location
    California, USA
    Posts
    520
    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.
    HTH,

  8. #8
    Join Date
    Mar 2002
    Location
    Bielefeld, Germany
    Posts
    69
    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.

  9. #9
    Join Date
    Jan 2007
    Location
    California, USA
    Posts
    520
    Please keep us informed on how you are doing. It sounds like a really neat project.

  10. #10
    Join Date
    May 2011
    Posts
    1

    Referencing forms in an external Project

    Seems like there never was a satisfactory solution to the question of how to call a form in another project using VBA code. We do this on a routine basis.

    My solution to this question with a detailed explanation and code samples can be found at:

    Moore Software Consultation And Design - Tips And Tricks - Call A Form In Another MDB Through A Reference

    Later,
    Bruce W. Moore

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •