Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Running code from different code libs (mde)

Status
Not open for further replies.

jphelps

Programmer
Jan 27, 2004
4
US
I have a significant set of generic code a reuse an many Access programs. I am trying to move it to an MDE and set it up for reuse with many other new project. I don't want to keep importing this code and generic forms for every project I write (plus there's the whole maintenance issue.)

OK, the codelib works fine. I call a routine, say "Main" from the new project testcodelib.mdb, and "Main" in the codelib works fine. However, if "Main" triggers a dialog form to load (the form is also in the MDE codelib and it don't matter whether it's a normal form or dialog/popup, etc) I can't seem to return control back to the testcodelib.MDB code.

How do I execute a sub, function, or trigger a macro or form in testcodelib.mdb from the codelib.MDE?

Any ideas, help, code examples are welcome.

Thanks
 
Hi jphelps

This is how I do it!

- Create a new module
- click on Tools > References

This will bring up the References dialog

From this select Browse, find the mde file and click on OK

Now this MDE file is associated to this database

You should now be able to CALL any of the routines/procedures you have created in the MDE file as if they were in the testDB.

Hope this helps!

Tiny


Perfection is Everything
If it worked first time we wont be here!
 
I have a reference. There is no problem running any routine or code or form that exists in the MDE. Here is and example of the problem:

'------------------------
'Code from testcodelib.mdb
Public Function Main()
'bunch of code here
SystemInitCheck
End Function

Public Sub StartSystem()
docmd.openform "frmMain"
End Sub
'------------------------


'------------------------
'Code in codelib.mde
Public Function SystemInitCheck()
'some code
If not AttachedTablesValid()
docmd.openform "frmResetAttachedTable"
end if
'all systems go

'StartSystem is from testcodelib.mdb above
StartSystem

End Function
'-----------------------------

So the program starts, Main runs, executes SystemInitCheck(). The code branchs at the "if" and opens "frmResetAttachedTable". ALl code in frmResetAttachedTable runs fine.

Now, once frmResetAttachedTable is completed, I can't seem to return to any forms, code, or macros in testcodelib.mdb. Also, SystemInitCheck won't find StartSystem or any other form, macro, code in testcodelib.mdb. I've tried every way I can think of to reference objects in testcodelib.mdb. What's crazy is I can "see" these objects, review properties (names, types, etc) but I can execute them.

Help - I'm stuck in codelib.mde and can't get out ;-{

 
JPhelps,

Are you saying that you never get to the "end if" right after the line that opens the form?

Jeremy

==
Jeremy Wallace
AlphaBet City Dataworks
Access Databases for Non-Profit Organizations

Please post in the appropriate forum with a descriptive subject; code and SQL, if referenced; and expected results. See thread181-473997 for more pointers.
 
First, thanks all you folks who are trying to help solve this!

Jeremy, regarding you question:

It does get to the "End If", and it opens the form, if necessary, just fine. It also tries to execute "StartSystem", but can't find "StartSystem".

From the code above, "StartSystem" is located in "testcodelib.mdb". Form "frmResetAttachedTable" is located in "codelib.mde". So, "textcodelib.mdb" can find and open and execute anything in "codelib.mde."

Here's the steps:
1) Code in textcodelib.mdb runs a function in "codelib.mde" called .
2) The function in "codelib.mde" opens a form which reside in "codelib.mde". It waits for use input.
3) Once that form opens, I can not seem to reference any object from "textcodelib.mdb" such as another form, macro, or other functions or subroutines such as "StartSystem". I can reference (execute) anything in "codelib.mde".
4) If I attempt to execute code(run "StartSystem" in this example) or open a form (Docmd.openform "fmrAssets") which resides in textcodelib.mdb, it will tell be it's not there.

Note however I something in the system know about them because if I put a breakpoint at the line that dies, I can go to the immediate window and execute:

?application.currentproject.Allforms.item("frmAssets").name it will show me it's name. I can do that with a number of the form properties. But I can't day:
Docmd.Openform "frmAssets"
It gives me an error code that it can't find the object.

To summarize:
It appears that if I execute code in codelib.mde, unless the code is a function that returns back to the caller, I can't get the execute stream out of codelib.mde and back into testcodelib.mdb.

If anyone wants to duplicate this, you can do it in about 2 minutes as follows:
1)Create a new MDB called codelib.mdb. Add one form called frmCodeLib. Put one button on it that executes:
Docmd.Openform "frmMain"

2)Create a second new mdb. All one form called "frmmain". Add one button on it that executes:
DoCmd.openform "frmCodeLib"
When you in the VB windoes. go to Tools > Refererence. click browse, and add a refernce to the codelib.mdb (you don't even need to make this an .mde yet)
3) Open the "frmMain" form. It should work find and you should get the frmCodeLib from opened.
4) Close the frmMain form, now click the button on the frmCodelib form. It will give you an error that it can't find "frmMain" BUT if you go to the immediate window and use the ?application... line above (change the form item to "frmmain") you will see it can in fact see it.

Sorry this is so long winded.
 
No need to pursue this. I've solved it.

Thanks for everyones help though.
 
What was the problem?

==
Jeremy Wallace
AlphaBet City Dataworks
Access Databases for Non-Profit Organizations

Please post in the appropriate forum with a descriptive subject; code and SQL, if referenced; and expected results. See thread181-473997 for more pointers.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top