Thanks for that Doc_Man. I've used the IN clause before but I'm trying to see if I a referenced code library would be useful to me. Anyone know of an example showing how it could be used? My version of Access, 2021 MSO (Version 2409 Build 16.0.18025.20030) 32-bit, does allow me to add an external accdb as a reference. ThxFor references to something that is passive in a back-end file, you can use the SQL ... FROM xxx IN path clause to specify a file and location. That ONLY works for tables as far as I know, because they are accessed using Server Message Block protocol, which is a file-sharing protocol. The only syntax for that location that doesn't require opening the file first is via SQL. (Which WILL implicitly open and later close the file for you.)
If an item is potentially active (queries, forms, reports, code) then you have to "persuade" it to become instantiated, which involves opening the file that contains that stuff. I believe that you need to open the database for anything else. Otherwise there is no visibility of content.
Adding a "reference" to an Access file might be trickier than you think because the VBA >> Tools >> References control form only shows you files of a specific subset of file types, and I don't recall that .ACCDx or .MDx qualifies for that kind of reference. If my other colleagues know of such a case, they will jump in to correct me, but I think what I said is more or less right.
How does it not allow you? I assume you mean not.My version of Access 2021 (Build 16.0.18025.20030) does allow me to add an external accdb as a reference.
Doc_Man mentioned it might not be possible but I myself am able to add an accdb.How does it not allow you? I assume you mean not.
Other than .accda not being available as an explicit file extension, there are all common Access file types listed in the Add Reference file dialog.Adding a "reference" to an Access file might be trickier than you think because the VBA >> Tools >> References control form only shows you files of a specific subset of file types, and I don't recall that .ACCDx or .MDx qualifies for that kind of reference.
The VBA development environment has a higher level view on all the opened projects, including referenced ones. You can even open and view(*) the code in the modules of the referenced file, including form class modules.In the db1 Immediate window I can go db2.Form_Form1.Visible = True and it opens the form. But if I put that in a module, it doesn't![]()
errHandler:
Call GlblErrMsg( _
sFrm:="ModDuplicateMeal", _
sCtl:="cboSelectaFood_AfterUpdate " _
)
Resume Cleanup
Resume
Public Sub OpenOtherDbForm(sFormName As String)
'sFormName = "Form_frmMain" 'de name as shown in vba code Explorer
'Database6 is the name of database shown in vba code explorer
'need te set a reference to the other database, Database6 in this case
'need reference to Microsoft Visual Basic for...
'Debug.Print VBE.ActiveVBProject.Name
VBE.VBProjects.Item("Database6").VBComponents(sFormName).Activate
'Debug.Print VBE.ActiveVBProject.Name
RunCommand (acCmdFormView) 'from design view to formview
End Sub
Public Sub OpenOtherDbForm(sFormName As String)
'module M_OpenForm with function OpenFormDb'
Database6.M_OpenForm.OpenFormDb (sFormName)
End Sub
''------------in Database6--------------
'module M_OpenForm
Public Sub OpenFormDb(sFormToOpen As String)
DoCmd.OpenForm sFormToOpen
End Sub
The simple way to expose classes in referenced databases - basically what I do with those in my Library database is in the database to be references add the code module below and run fClassMultiUse before before use.Yes, you can absolutely set a reference to another access database without the referenced file being open. Any public sub in any standard module is then visible in the application that holds the reference.
...
You can expose classes from a referenced database
....
Option Compare Database
Option Explicit
Public Function fClassMultiUse() As Boolean
On Error GoTo Err_fClassMultiUse
Dim blRet As Boolean, i As Integer
With VBE.ActiveVBProject.VBComponents
For i = 30 To .Count
If .Item(i).Type = 2 Then ' Class module (vbext_ct_ClassModule)
With .Item(i).Properties.Item(2) ' "Instancing"
If .Value <> 5 Then .Value = 5
End With
End If
Next i
End With
blRet = True
Exit_fClassMultiUse:
fClassMultiUse = blRet
Exit Function
Err_fClassMultiUse:
Select Case Err.Number
Case Else
MsgBox "Error No.: " & Err.Number & vbNewLine & vbNewLine & _
"Description: " & Err.Description & vbNewLine & vbNewLine & _
"Procedure: fClassMultiUse" & vbNewLine & _
"Module: basUtility", , "Error: " & Err.Number
Resume Exit_fClassMultiUse
End Select
End Function
I distribute my Library file as a companion to the FE, so each user has his own copy.I'm sure there would be additional considerations were I to deploy an approach like this to a production environment, such as making sure that all user Front Ends referenced the same common library accdb appropriately.
The oldest code I can find in my Library file was written in 2004, so it's not super new.has that ability been present for a long time?
I don't recall when I first started doing so. It has code in it from 2010, so that may be close to the beginning for my use. I never tried with an mdb. I suspect it would be possible. Maybe it's a good time to start up an old VM and find out.Well, I have learned something today. Thanks, colleagues, for pointing out that this can be done. Just a side question... has that ability been present for a long time? I didn't think it was available in earlier versions of Access.
Perhaps this old thread on this forum can help you with some examples. Search and look up this threat:
"Opening a form in a library and retrieving a returned value"