By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,829 Members | 673 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,829 IT Pros & Developers. It's quick & easy.

Multiple Library databases

Expert 100+
P: 1,430
I have a main database and 2 referenced library databases.

The 3 databases all have forms in them.

I want to be able to open any of those forms, regardless of which database I am in. (4 possible combinations)

At the moment I use
Expand|Select|Wrap|Line Numbers
  2. Function OpenFrm(FrmName, Optional Vew, Optional Filtr, Optional Whre, Optional Datmode, Optional WindMode, Optional Args)
  4.     On Error GoTo OpenFrm_Error
  6.     DoCmd.OpenForm FrmName, , , , , , Args
  8.     Exit Function
  10. OpenFrm_Error:
  11.     If Not IsMissing(Args) Then
  12.         If Nz(Args) = "Application Quit" Then
  13.             Resume Next
  14.         End If
  15.     Else
  16.         MsgBox "Error " & Err.Number & " (" & Err.Description & ") in procedure OpenFrm of form " & FrmName
  17.     End If
  19. End Function
which I can call from the Library database and it opens a form in the main databese.

So for example, how do I refer to a form in Library2 from Library1 or how do I refer to a form in Library1 when I am in the main database?


Jan 31 '18 #1
Share this Question
Share on Google+
5 Replies

Expert Mod 15k+
P: 31,418
MSAccess Help:
FormName Required Variant. A string expression that's the valid name of a form in the current database. If you execute Visual Basic code containing the OpenForm method in a library database, Microsoft Access looks for the form with this name first in the library database, then in the current database.
From this I would gather you can't do it using DoCmd.OpenForm(). Do bear in mind there are other ways of opening (Instantiating) Forms from VBA though.
Feb 1 '18 #2

Expert 100+
P: 1,430
Thanks for your observations.

Th code I posted works well to open a form in the main database from either one of the library databases.

The problem is having failed to find the form in the first library database, then failing to find it in the current database, I need it to ave a go at opening the form in the second library database.

Feb 2 '18 #3

Expert Mod 15k+
P: 31,418
Pretty much what I understood from your original post TBF.

It would seem clear then that form instantiation is what you need to use instead. DoCmd.OpenForm() is unable to do what you need in those circumstances.
Feb 2 '18 #4

Expert 100+
P: 1,430
So I expect I need some sort of command like
Library1.DoCmd.OpenForm "FormName"
Library2.DoCmd.OpenForm "FormName"
with suitable error checks so that if the form is not found in the current library (Library1), it will have a go at finding in the next library.
That looks like a loop in case there are more that 2 referenced libraries. Only when it fails in all of them should I get the error message of "Form not found"

So we get down to the correct syntax of
Library1.DoCmd.OpenForm "FormName"

Feb 2 '18 #5

Expert Mod 15k+
P: 31,418
You may want to reread my last post more carefully (Caerphilly? - No) Phil. It won't be possible to use DoCmd.OpenForm() (Full stop).

Variations of that would be to an Automated instance of Access only. That is not your situation and cannot help you.

The only way I know of opening forms in the way you need is to instantiate the Form class variables in your code.
Feb 2 '18 #6

Post your reply

Sign in to post your reply or Sign up for a free account.