Go Back   Access World Forums > Microsoft Access Discussion > Modules & VBA

 
Reply
 
Thread Tools Rating: Thread Rating: 2 votes, 5.00 average. Display Modes
Old 09-21-2001, 11:56 AM   #1
bah
Guest
 
Posts: n/a
Executing a module from another DB

I am in database A and need to run a standard module that is in database B in the background from database A.

What is the VB code to run a module from a different database? I know how to open the module using the following code - is there a way to change the syntax so that it points to this module in a different database?

DoCmd.OpenModule "modules_excel_input_files"

  Reply With Quote
Old 09-21-2001, 04:19 PM   #2
cargobay 69
Member
 
Join Date: Apr 2001
Location: Washington State, USA
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
cargobay 69
You cannot open a module that is in database B from within database A. You will have to copy the module from B to A then run the needed procedure from A as any other local procedure.

Darrin@CB69
cargobay 69 is offline   Reply With Quote
Old 09-22-2001, 07:00 PM   #3
Pat Hartman
Super Moderator
 
Join Date: Feb 2002
Location: Stratford,Ct USA
Posts: 27,336
Thanks: 13
Thanked 1,403 Times in 1,337 Posts
Pat Hartman is a glorious beacon of light Pat Hartman is a glorious beacon of light Pat Hartman is a glorious beacon of light Pat Hartman is a glorious beacon of light Pat Hartman is a glorious beacon of light Pat Hartman is a glorious beacon of light
You CAN do this. I don't have any code to post but I'll post the help entry from A97 that should get you started.

Set a Reference to a Visual Basic Project in Another Microsoft Access Database

Each Microsoft Access database includes a Visual Basic project. The Visual Basic project is the set of all modules in the project, including both standard modules and class modules. Every Microsoft Access database, library database, or add-in contained in an .mde file includes a Visual Basic project.
The name of the database and the name of the project can differ. The name of the database is determined by the name of the .mdb (or .mda or .mde) file, while the name of the project is determined by the setting of the Project Name option on the Advanced tab of the Options dialog box, available by clicking Options on the Tools menu. When you first create a database, the database name and project name are the same by default. However, if you rename the database, the project name doesn't automatically change. Likewise, changing the project name has no effect on the database name.

You can set a reference from a Visual Basic project in one Microsoft Access database to a project in another Microsoft Access database, a library database, or an add-in contained in an .mde file. Once you've set a reference, you can run Visual Basic procedures in the referenced project. For example, the Northwind sample database includes a module named Utility Functions that contains a function called IsLoaded. You can set a reference to the project in the Northwind sample database from the project in the current database, and then call the IsLoaded function just as you would if it were defined within the current database.

To set a reference to the project in the Northwind sample database from another project:

1. Open the Module window.
2. On the Tools menu, click References, and click Browse in the References dialog box.
3. In the Files Of Type box, click Databases (*.mdb, *.mda, *.mde).
4. Locate the Northwind.mdb file. If you've installed this file, it will be in the \Program Files\Microsoft Office\Office\Samples folder by default.
5. Click OK.

You should now see "Northwind.mdb" in the list of available references in the References dialog box.

Notes

Set a reference to the project in another Microsoft Access database when you want to call a public procedure that's defined within a standard module in that database. You can't call procedures that are defined within a class module or procedures in a standard module that are preceded with the Private keyword.
You can set a reference to the project in a Microsoft Access database only from another Microsoft Access database.

You can set a reference to a project only in another Microsoft Access 97 database. To set a reference to a project in a database created in a previous version of Microsoft Access, first convert that database to Microsoft Access 97.
If you set a reference to a project or type library from Microsoft Access and then move the file that contains that project or type library to a different folder, Microsoft Access will attempt to locate the file and reestablish the reference. If the RefLibPaths key exists in the registry, Microsoft Access will first search there. If there's no matching entry, Microsoft Access will search for the file first in the current folder, then in all the folders on the drive. You can create the RefLibPaths key by using the Registry Editor in Windows, under the registry key \HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\8.0\ Access. For more information about using the Registry Editor, see your Windows documentation.

__________________
Bridge Players Still Know All the Tricks
Pat Hartman is offline   Reply With Quote
Old 12-10-2017, 07:47 AM   #4
GMc87
Newly Registered User
 
Join Date: Dec 2017
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
GMc87 is on a distinguished road
Re: Executing a module from another DB

Hi All

I have been using the site for a while now but just joined up so i can post for some help .
I have done a couple of days training on access but only been using it for just under a year so still fairly new to it.

I know this is a very old post but it was actually relevant and useful for something i'm doing in access 2010.

I was able to use this post to reference another db and call a sub but i am having an issue when i try to reference my menu form in the code.

So my code in one db opens another db then i am trying to call a sub that will hide buttons depending on who has opened the db. The sub is called fine but its when i reference my form it says it can't find it.

The forms is open and the code works when i run from the db that it is located in. I tried setting visible property from the both and it cant seem to find it.

My code is just a list like below.

Any idea why this isn't working? do i need to reference the db before the form?

Forms![Menu]![Command0].Visible = True
Forms![Menu]![Command2].Visible = True
Forms![Menu]![Command3].Visible = True

Thanks
G
GMc87 is offline   Reply With Quote
Old 12-10-2017, 08:00 AM   #5
Solo712
Newly Registered User
 
Solo712's Avatar
 
Join Date: Oct 2012
Posts: 653
Thanks: 13
Thanked 102 Times in 99 Posts
Solo712 will become famous soon enough
Re: Executing a module from another DB

Quote:
Originally Posted by cargobay 69 View Post
You cannot open a module that is in database B from within database A. You will have to copy the module from B to A then run the needed procedure from A as any other local procedure.

Darrin@CB69
Darrin, make sure you consult some sources before making categorical statements !

https://bytes.com/topic/access/answe...ode-another-db

bah, see above for an example.


Best,
Jiri
__________________
Dyslexics of the world untie !
Solo712 is offline   Reply With Quote
The Following User Says Thank You to Solo712 For This Useful Post:
GMc87 (12-10-2017)
Old 12-10-2017, 08:18 AM   #6
GMc87
Newly Registered User
 
Join Date: Dec 2017
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
GMc87 is on a distinguished road
Re: Executing a module from another DB

Hi Jiri

Thanks that works great, i was just using call sub before which wasn't working

GMc
GMc87 is offline   Reply With Quote
Old 12-10-2017, 08:29 AM   #7
Solo712
Newly Registered User
 
Solo712's Avatar
 
Join Date: Oct 2012
Posts: 653
Thanks: 13
Thanked 102 Times in 99 Posts
Solo712 will become famous soon enough
Re: Executing a module from another DB

Quote:
Originally Posted by GMc87 View Post
Hi Jiri

Thanks that works great, i was just using call sub before which wasn't working

GMc
You are welcome.

Best,
Jiri

__________________
Dyslexics of the world untie !
Solo712 is offline   Reply With Quote
Old 12-10-2017, 08:30 AM   #8
CJ_London
Super Moderator
 
Join Date: Feb 2013
Location: UK
Posts: 10,212
Thanks: 39
Thanked 3,302 Times in 3,198 Posts
CJ_London is just really nice CJ_London is just really nice CJ_London is just really nice CJ_London is just really nice CJ_London is just really nice
Re: Executing a module from another DB

@Solo - make sure you check the date of the post- Darrin has probably retired by now....
__________________
CJ_London
_______________________
A little thanks goes a long way. If you have found this post useful, please tick the thanks button
CJ_London is offline   Reply With Quote
Old 12-10-2017, 08:33 AM   #9
Solo712
Newly Registered User
 
Solo712's Avatar
 
Join Date: Oct 2012
Posts: 653
Thanks: 13
Thanked 102 Times in 99 Posts
Solo712 will become famous soon enough
Re: Executing a module from another DB

Quote:
Originally Posted by CJ_London View Post
@Solo - make sure you check the date of the post- Darrin has probably retired by now....
Right! I am trusting by nature!

Best,
Jiri

__________________
Dyslexics of the world untie !
Solo712 is offline   Reply With Quote
Reply

Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Forum Jump




All times are GMT -8. The time now is 04:48 AM.


Microsoft Access Help
General
Tables
Queries
Forms
Reports
Macros
Modules & VBA
Theory & Practice
Access FAQs
Code Repository
Sample Databases
Video Tutorials

Sponsored Links

How to advertise

Media Kit


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
(c) copyright 2017 Access World