Question : Missing References

I have a database which resides on a network drive. Occasionally when a user tries to log in they get a Compile Error - cannot find project or library. If I then check the references in the module tab the utility.mda is referred to as missing. If you then check the path the file is infact there. I have tried to add the reference again and this seems to work but only for a while. Other users including myself can get in with the reference pointing to the same utility.mda.
The compile error occurs as the autoexec macro tries to open a form.  

Answer : Missing References

The idea is pretty simple:

References.Remove References(strDatabase)
References.AddFromFile "H:\Path\" + strDatabase + ".mde"

I used only one reference so I used something like this (only I used a function to find the app path and used that instead of the "H:\Path" bit)

This is the actual code I used:

Function ReReference(strDatabase As String) As Boolean
Dim DBPath As String
Dim RefPath As String, RefFile As String

On Error GoTo lbl_Err

    DBPath = Left$(DBEngine(0)(0).Name, LastInstr(DBEngine(0)(0).Name, "\"))
    RefPath = Left$(References(strDatabase).FullPath, LastInstr(References(strDatabase).FullPath, "\"))
    RefFile = Right$(References(strDatabase).FullPath, Len(References(strDatabase).FullPath) - LastInstr(References(strDatabase).FullPath, "\"))
    If RefPath <> DBPath Then
        'ReReferencen want het path is verkeerd
        If msgbox("ReReferencing " & References(strDatabase).FullPath & " to " & DBPath & RefFile, vbOKCancel, "Reference " & strDatabase) = vbOK Then
            References.Remove References(strDatabase)
            References.AddFromFile DBPath & RefFile
        End If
    End If

    ReReference = True

lbl_Exit:
    Exit Function
   
lbl_Err:
    msgbox "ReReference:(" & Err & ")" & Error$
    ReReference = False
    Resume lbl_Exit

End Function

Called (from a macro) with  ReReference("LibraryName") (where LibraryName is without the extension)

If you want to run through all references probable you could use some "For Each ref In References" loop.

The trouble is though that when a reference is missing you get a compile error. And thus the code wont run. However I created a ReReference macro that would fix the reference and I had some success with it. In the end I got fed up with the references and gave up completely (at least for the ones you can drop)
Random Solutions  
 
programming4us programming4us