Open specific form in external DB (1 Viewer)

Zydeceltico

Registered User.
Local time
Today, 12:12
Joined
Dec 5, 2017
Messages
843
Hi All -

I am developing a db (Access 2016) for our company that allows us to answer a variety of questions related to production. Our company also has a legacy database (an earlier version of Access - 2007 I think). This database used to provide a 1-stop shop for a large variety of records keeping for various and unrelated activities. Some of those tables (and forms) are still relevant and have data input forms associated with them. These tables and forms are not represented in the new db. In fact, the handful that I am thinking of work quite well just as they are and I see no need to reinvent the wheel.

In the new db (dbMyNewDB) I have a form (frmNewMenuForm) that acts like a switchboard in that it has a lot of command buttons on it that are used to open various inspection forms in dbMyNewDB. I would like to add a button on frmNewMenuForm that opens a specific form (frmWorksGreat) on the legacy db (dbOldDB) that allows data input into tblAlreadyBuiltTable in dbOldDB.

How do I do that?

Both dbs will live on the same network server but in different folders.

Thanks in advance.

Tim
 

pbaldy

Wino Moderator
Staff member
Local time
Today, 09:12
Joined
Aug 30, 2003
Messages
36,125
I won't say it can't be done, but personally I'd probably import the form into the new db, link to the same table from the new db, and just open that form.
 

theDBguy

I’m here to help
Staff member
Local time
Today, 09:12
Joined
Oct 29, 2018
Messages
21,474
Hi,

Can’t test anything right now but if you open db2 using automation, then you should be able to use DoCmd to open the other form. For example,

db2.DoCmd.OpenForm “FormName”

Sent from phone...
 

Zydeceltico

Registered User.
Local time
Today, 12:12
Joined
Dec 5, 2017
Messages
843
I won't say it can't be done, but personally I'd probably import the form into the new db, link to the same table from the new db, and just open that form.

I think you're right. I'll give it a go. Is there anything special I need to be aware of when linking the imported form to the old table?

Thanks,

Tim
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 11:12
Joined
Feb 28, 2001
Messages
27,187
Once you import the form AND link the data from the other DB, just remember to go in and update the imported form's .RecordSource before deploying. AND of course, test it before deploying. AND have a pre-import copy of the DB front-end standing by a backup in case things go west on you.
 

Solo712

Registered User.
Local time
Today, 12:12
Joined
Oct 19, 2012
Messages
828
Interesting, an almost identical OP was run here two years ago. CJ London gave the most obvious reply.

https://access-programmers.co.uk/forums/showpost.php?p=1509685&postcount=2

Another way to gain access to forms in another database is to create within them a general reference to the local database "CodeDb" instead of the regular "CurrentDb", then put them in a "library", a include them in the code "References". I use this technique to share data among several databases.

Best,
Jiri
 

Zydeceltico

Registered User.
Local time
Today, 12:12
Joined
Dec 5, 2017
Messages
843
Interesting, an almost identical OP was run here two years ago. CJ London gave the most obvious reply.

https://access-programmers.co.uk/forums/showpost.php?p=1509685&postcount=2

Another way to gain access to forms in another database is to create within them a general reference to the local database "CodeDb" instead of the regular "CurrentDb", then put them in a "library", a include them in the code "References". I use this technique to share data among several databases.

Best,
Jiri

I've been toying with this notion as well. Thanks for validating my thought.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 12:12
Joined
May 21, 2018
Messages
8,529
You can open another form from another DB within your DB and use all the code stored in the external DB.

In the external DB add this function
Code:
Public Function openForm(formName, Optional view As AcFormView = acNormal, Optional filterName, Optional whereCOndition, Optional datamode As AcFormOpenDataMode = acFormPropertySettings, Optional windowMode As AcWindowMode = acWindowNormal, Optional openArgs) As Access.Form
    DoCmd.openForm formName, view, filterName, whereCOndition, datamode, windowMode, openArgs
    Set openForm = Forms(formName)
End Function

Now add the external database as a reference using the browse feature.

To call that form and have it show up in the current db
Code:
  Dim frm As Access.Form
  Set frm = library.OpenForm("frmTest")

Where library is the name of the external database (code project). This is how you can build a large library of code and reference it from another database.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 12:12
Joined
May 21, 2018
Messages
8,529
I would not recommend CJ's method of opening another instance. That is pretty clunky because you have two instances of Access running and visible. Unless that is what you want.
 

MajP

You've got your good things, and you've got mine.
Local time
Today, 12:12
Joined
May 21, 2018
Messages
8,529
another thing that was recently asked was if you could trap events from an external form. In this example I open a form in the external database and trap the close event of the external form
Code:
Option Compare Database
Option Explicit
 Dim WithEvents extfrm As Form
Private Sub cmdExternal_Click()
  Set extfrm = library.OpenForm("frmLibrary")
  extfrm.OnClose = "[Event Procedure]"
End Sub

Private Sub extfrm_Close()
  MsgBox "External Form Closed"
End Sub
 

The_Doc_Man

Immoderate Moderator
Staff member
Local time
Today, 11:12
Joined
Feb 28, 2001
Messages
27,187
Just to be pedantic, MajP, and this is one that I don't know. Perhaps you do.

In the case where you create a new process for Access using some variant of command shell to launch it, and you manipulate the 2nd process using Send Keys, you would have two distinct processes and two workspaces. In that case, can the first DB see the second DB's events? I would offhand say no.

I would agree that if you just open the 2nd database (DoCmd.OpenDatabase e.g.) so that you now have two databases open in the same process, you are in the same workspace, and events are a function of the process. So any events of the 2nd DB in that case would be seen by the process. I say that because when you do event-based programming in VB6, e.g., you get events even though Access isn't involved. When I worked with Paradox for Windows, we also got events. So events aren't an Access thing. They are a Windows process-level thing.
 

Users who are viewing this thread

Top Bottom