Creating a library reference for distributed applications
If you're distributing your application, references stay intact only if the calling database and the library database are in the same path. For example, if the main database is in C:\myapp on your machine, and if the library database is in C:\myapp\library, the reference remains intact as long as the library database is located in C:\myapp\library. If the path won't remain consistent upon distribution, your application's users must manually adjust the reference or you must create the reference with VBA code.
The following procedure creates a reference to the file whose name is passed as an argument. In order for this function to work, the full filename with path must be passed:
bResult = CreateReference("C:\My Documents\MyLib.accdb").
The function is
Public Function CreateReference(strFileName As String) _ As Boolean Dim ref As Reference On Error GoTo HandleError Set ref = References.AddFromFile(strFileName) CreateReference = True ExitHere: Exit Function HandleError: MsgBox Err & ": " & Err.Description CreateReference = False Resume ExitHere End Function
Tip: You can verify that a reference is set by using the ReferenceFromFile function. To verify a reference, pass the function, the full path, and the filename like this:
bResult = ReferenceFromFile("C:\Windows\System32\mscal.ocx")
Here's the function, which returns True if the reference is valid and False if it isn't:
Public Function ReferenceFromFile(strFileName As String) _ As Boolean Dim ref As Reference On Error GoTo HandleError For Each ref In References If StrComp(ref.FullPath, strFileName) = 0 Then ReferenceFromFile = True Exit For End If Next ref ExitHere: Exit Function HandleError: MsgBox Err & ": " & Err.Description ReferenceFromFile = False Resume ExitHere End Function
With the References collection, the primary concern of using and distributing libraries - losing references upon distribution - is now gone. However, library databases still have one major drawback: Access libraries don't support circular references. This means that the code in your library databases can't reference variables or call procedures that exist in your parent database.
Whether you distribute your application as one database or as a primary database that uses library databases, if your applications are static (they don't allow modification of objects by end users or wizards and don't perform object modifications on themselves), you should always distribute the databases in a fully compiled state so that your users experience the highest level of performance.
In this tutorial:
- Optimizing Access Applications
- Understanding Module Load on Demand
- Using the .accdb Database File Format
- Distributing .accde Files
- Understanding the Compiled State
- Application's code into a compiled state
- Distributing applications in a compiled or uncompiled state
- Creating a library reference for distributed applications
- Improving Absolute Speed
- Getting the most from your tables
- Getting the most from your queries
- Getting the most from your forms and reports
- Using bitmaps on forms and reports
- Getting the most from your modules
- Using control variables
- Eliminating dead code and unused variables
- Improving Perceived Speed
- Loading and keeping forms hidden
- Speeding up the progress meter display
- Working with Large Access Databases
- Recognizing that compiling and compacting
- Using the decompile option
- Detecting an uncompiled database and automatically recompiling