The best solution is to limit references in your Access MDB to internal Access components. This would be the Access reference, the VBA reference, and the DAO reference. All other outside libraries should be used through late binding. If you're using the File System Object, for instance, instead of this (with a reference to the Windows Script Host Object Model):
Dim objFSO As New FileSystemObject
If objFSO.FolderExists("\\d9m09521\WB\") Then
...
End If
you would remove the reference and convert it to this:
Dim objFSO As Object
Set objFSO = CreateObject("Scripting.FileSystemObject")
If objFSO.FolderExists("\\d9m09521\WB\") Then
...
End If
If you're concerned about the performance hit of initializing the FSO each time you use it, you can cache a reference to it. I usually use a static variable inside a function to return an object like this:
Public Function FSO() As Object
Static objFSO As Object
If objFSO Is Nothing Then
Set objFSO = CreateObject("Scripting.FileSystemObject")
End If
FSO = objFSO
End Function
Now, you might want to get fancy and also be able to tear down the instantiated object, in which case you'd do something like this:
Public Function FSO(Optional bolCloseObject As Boolean = False) As Object
Static objFSO As Object
If bolCloseObject Then
Set objFSO = Nothing
Exit Function
End If
If objFSO Is Nothing Then
Set objFSO = CreateObject("Scripting.FileSystemObject")
End If
FSO = objFSO
End Function
In any event, the whole point is that late binding resolves the location of the outside libraries at runtime and thus won't break, except if the outside library is not installed or not properly registered. With late binding, you can trap for both of those conditions, but with early binding, your whole Access app simply breaks.
--
David W. Fenton
David Fenton Associates