Avatar of stephenlecomptejr
stephenlecomptejr
Flag for United States of America asked on

Microsoft Access: How to open a form referenced in another Microsoft Access database?

I'm having trouble with the correct syntax to open a form that is pulled in as a referenced Microsoft Access database file as .accdb.  The database that is referenced is called systemBA.accdb.   The error I get obviously is:  Run time error '2102': the form name 'sys_fStartup' is misspelled or refers to a form that doesn't exist.    

The code line is:  (highlighted in yellow below per images) DoCmd.OpenForm "sys_fStartup"
How do I change it to pull from the Database(systemBA) as shown in the second image?

Appreciate the help in advance!






MicrosoftMicrosoft AccessDatabases

Avatar of undefined
Last Comment
Fabrice Lambert

8/22/2022 - Mon
ste5an

This requires automation. E.g.

Dim AccessInstance As Access.Application
Set AccessInstance = New Access.Application
AccessInstance.OpenCurrentDatabase ("pathToYourReferencedDatabase")
AccessInstance.DoCmd.OpenForm "YourForm"

Open in new window

Fabrice Lambert

The suggested solution work but if the targeted database has any  startup option such as autostart macro or startup form, you might see bad surprises.

IMO, it will be better to reference the 2nd database as a library, and instanciate the desired form.
stephenlecomptejr

ASKER
Fabrice, are you talking about converting it to a .dll in C++ .net?  If not, may get more details on getting that done?
This is the best money I have ever spent. I cannot not tell you how many times these folks have saved my bacon. I learn so much from the contributors.
rwheeler23
Fabrice Lambert

Nope, Ms Access databases can be referenced like any com library.
stephenlecomptejr

ASKER
But sir, do you not see in the third image where I've already done that?
Fabrice Lambert

But sir, do you not see in the third image where I've already done that?
In such case, you don't need  instanciate a 2nd ms access application.
Just write a couple of helper functions in the "library" that will retrieve an instance of the desired form.

See the attached sample.
(Important: both databases must be in the same directory).

*EDIT*
Attached sample is in my next answer.


Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
ste5an

hmm, doesn't work here.

Capture.PNG
ASKER CERTIFIED SOLUTION
Fabrice Lambert

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
stephenlecomptejr

ASKER
Wow.  How does the MS Access file know the correct reference when downloaded?  Does it automatically change the reference if the database is in the same location as the other?
Fabrice Lambert

This is due to references resolutions mechanisms:
If the file match the absolute path, use it.
Else, if the file is in the project path, use it.
Else, if the file is in the system's environment search path, use it.
Else, throw an error.
Experts Exchange has (a) saved my job multiple times, (b) saved me hours, days, and even weeks of work, and often (c) makes me look like a superhero! This place is MAGIC!
Walt Forbes
stephenlecomptejr

ASKER
what would be the project path or system's environment search path?

Fabrice Lambert

 project path = the database's directory.
system's environment search = windows environment variable.
stephenlecomptejr

ASKER
sorry I thought the absolute path would be the database's directory - then what is the absolute path then?

Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Fabrice Lambert

The absolute path is the one you set in the reference's window.