Results 1 to 4 of 4
  1. #1
    Join Date
    Dec 2004
    Location
    Sunshine Coast, Australia
    Posts
    52

    Question Unanswered: list missing references

    Hi is there any code you can run to list the missing references of an MDE at runtime?

  2. #2
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    i have code to list your master-version references
    i have code to runtime-auto-reference those master-version references from .mde

    ...missing: no

    izy
    currently using SS 2008R2

  3. #3
    Join Date
    Dec 2004
    Location
    Sunshine Coast, Australia
    Posts
    52
    hi izy, how do you do it please?

  4. #4
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    here's the outline of how to list current references.

    run (a modification of) it in something that works (e.g. your development machine) to see what references you have set:

    Private Sub butGo_Click()
    Dim intRef As Integer
    Dim strMsg As String

    If Application.References.Count = 0 Then
    MsgBox "ZERO references found...", vbInformation, "No References"
    Else
    For intRef = 1 To Application.References.Count
    strMsg = strMsg & Application.References(intRef).Name & ": "
    strMsg = strMsg & Application.References(intRef).FullPath & vbCrLf
    Next
    End If
    debug.print strMsg
    End Sub

    you need the results from the above to set up the below



    here's the outline of how to set references from code: it is code in a FORM (so that it unloads from memory once it's job is done). i set this form as the startup form in all my applications (...obviously with modifications to suit the application!)

    be warned ---- it uses imghelp to scan the entire disk for the files associated with missing references. if you have 5 missing references and a big disk, you have time for a coffee while it runs. this is a ONE-TIME thing the first time an application runs.

    but take heart - once the missing reference has been fixed, the next time you run the application, the form loads, checks references, and unloads in a few milliseconds, opening the form defined by the constant frmOpen.

    Option Compare Database
    Option Explicit


    '' ''
    '' Utility: LibLoad ''
    '' ''
    '' Check references and if missing attempt to locate the appropriate file ''
    '' on drive c: and if found attempt to create the reference automatically ''
    '' ''
    '' THE PROGRAMMER IS RESPONSIBLE FOR SETTING PROPERTIES IN LibLoad0() ''
    '' ''



    Private Declare Function SearchTreeForFile Lib "imagehlp" (ByVal SearchRoot As String, ByVal FileName As String, ByVal Foundfile As String) As Boolean

    Private Sub LibLoad0()


    '' ''
    '' BEGIN PROGRAMMER-SET PROPERTIES BLOCK 1 of 2 ''
    '' ''
    '' Declare the number of references to be checked/set as Const maxRefs ''
    '' Declare which form to open on successful conclusion as Const frmOpen ''
    '' ''
    Const maxRefs = 4
    Const frmOpen = "frmMain"
    '' ''
    '' END PROGRAMMER-SET PROPERTIES BLOCK 1 of 2 ''
    '' ''




    Dim refName(1 To maxRefs) As String
    Dim refFile(1 To maxRefs) As String
    Dim loupe As Integer
    Dim msg As String
    Dim shownAlready As Boolean




    '' ''
    '' BEGIN PROGRAMMER-SET PROPERTIES BLOCK 2 of 2 ''
    '' ''
    '' Fill arrays with name/file data using the format: ''
    '' refName(1) = "DAO" 'the name of the reference ''
    '' refFile(1) = "dao360.dll" 'the file name.ext ''
    '' refName(2)...and so on for each of maxRefs entries ''
    '' ''
    refName(1) = "DAO"
    refFile(1) = "dao360.dll"
    refName(2) = "Outlook"
    refFile(2) = "msoutl9.olb"
    refName(3) = "Excel"
    refFile(3) = "EXCEL9.olb"
    refName(4) = "Office"
    refFile(4) = "MSO9.DLL"
    '' ''
    '' END PROGRAMMER-SET PROPERTIES BLOCK 2 of 2 ''
    '' ''



    shownAlready = False
    For loupe = 1 To maxRefs
    If Not LibLoad1(refName(loupe)) Then
    If Not shownAlready Then
    msg = "Missing library reference(s)! The system will now attempt to "
    msg = msg & "locate the library file and automatically set a reference "
    msg = msg & "to it. This process will take a few minutes and cause a lot of "
    msg = msg & "disk activity. This is a one-time process and will not be necessary "
    msg = msg & "the next time you use this application"
    MsgBox msg, vbInformation, "Missing Reference"
    shownAlready = True
    End If
    If Not LibLoad2(refFile(loupe)) Then
    msg = "Could not find " & refName(loupe) & ": " & refFile(loupe)
    msg = msg & vbCrLf & "Application will abort."
    MsgBox msg, vbCritical, "ABORTING!"
    DoCmd.Quit
    End If
    End If
    Next
    DoCmd.Close acForm, "utilityLibLoad"
    DoCmd.OpenForm frmOpen
    End Sub

    Private Function LibLoad1(NameOfRef As String) As Boolean
    Dim intRef As Integer
    If Application.References.Count = 0 Then
    MsgBox "ZERO references found. Trying to continue...", vbInformation, "No References"
    Else
    For intRef = 1 To Application.References.Count
    If Application.References(intRef).Name = NameOfRef Then
    LibLoad1 = True
    Exit Function
    End If
    Next
    End If
    LibLoad1 = False
    End Function

    Private Function LibLoad2(NameOfFile As String) As Boolean
    On Error GoTo err_LibLoad2
    Dim ref As Reference
    Dim Foundfile As String
    Foundfile = String(260, " ")
    If SearchTreeForFile("c:\", NameOfFile, Foundfile) Then
    Set ref = References.AddFromFile(Foundfile)
    LibLoad2 = True
    Else
    LibLoad2 = False
    End If
    exit_LibLoad2:
    Exit Function
    err_LibLoad2:
    MsgBox Err.Number & ": " & Err.Description, vbCritical, "Fatal error in LibLoad2"
    LibLoad2 = False
    Resume exit_LibLoad2
    End Function

    Private Sub Form_Load()
    LibLoad0
    End Sub


    note that i STRONGLY recommend you only use the NAME.EXT of the library file even though it takes a while for imghelp to find it. using the full drive-path-name.ext will fail if a user's installation is in strange directories.
    if you CONTROL the installation image of ALL your users, then obviously you can skip the search bit.

    LibLoad fails when the drive-path-name.ext of a library is longer than 260 characters.

    good luck: let me know how it goes.

    izy
    Last edited by izyrider; 01-14-05 at 08:51. Reason: typos in the text (code's OK tho)
    currently using SS 2008R2

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •