• Switch References on and off with code (Acc 97 sr2 on 95b)

    Home » Forums » AskWoody support » Productivity software by function » MS Access and database help » Switch References on and off with code (Acc 97 sr2 on 95b)

    Author
    Topic
    #373411

    I have 2 Developer addins on my machine that knowone else has. Can I set a toggle button to switch these references off before I create the MDE that everyone else uses and then toggle them back on?

    OR

    CmdButton to switch off before building MDE and code to auto switch on on loading? IF yes, I’ll need the coding please.

    Viewing 1 reply thread
    Author
    Replies
    • #600145

      Hi Allen, You can add and remove references through code by using the AddFromCode and Remove methods of the References collection. In Access Help Index look for the topic “References Collection”; it gives coding examples. But if the references are needed for the project that you are going to distribute as an MDE wouldn’t they need to be toggled on at the time you build the MDE? I probably am not understanding what you want to. Each Reference also has a property named Builtin that is True if it is needed for Access to function properly, so you’ll need to always keep those set. Here’s some code you can try just to see what references are currently set, whether they are built-in, and if any are broken.
      Dim refx As Reference
      For Each refx In Application.References
      MsgBox refx.Name & “: ” & refx.FullPath & vbCrLf & _
      “Major : ” & refx.Major & ” Minor: ” & refx.Minor & vbCrLf _
      & “Builtin: ” & refx.BuiltIn & ” Kind: ” & refx.Kind

      If refx.IsBroken Then
      MsgBox refx.Name & ” is broken!”
      End If

      Next refx

    • #600154

      If they were indeed added as references, I might be able to help. If they were added some other way, this probably is useless to you.

      Here’s a function to remove a reference. This was based on A97 help way back when and will work in later versions as well.

      Function RemoveRef(strRefName As String) As Boolean
        Dim ref As Access.Reference
      
        On Error GoTo RemoveRef_err
        ' Return object representing existing reference.
        Set ref = Application.References(strRefName)
        ' Remove reference from collection.
        Application.References.Remove ref
        RemoveRef = True
      
      RemoveRef_exit:
        Exit Function
      RemoveRef_err:
        MsgBox "RemoveRef error #" & Err & "--" & Err.Description
        RemoveRef = False
        Resume RemoveRef_exit
      End Function

      The catch is that the name of the ref isn’t what you see in the references list *or* the name of the library file. Here’s a routine to debug.print the references so you can see the name to use. You can’t remove the built-in refs, of course.

      Public Function EnumRefs()
        Dim ref As Access.Reference
        
        For Each ref In Application.References
          Debug.Print ref.Name, ref.FullPath, ref.BuiltIn
        Next
      End Function

      And finally, heres a routine to add a reference:

      Function AddRef(strRefPath As String) As String
      ' Example:  AddRef "C:Program FilesCommon FilesMicrosoft SharedDAOdao360.dll"
        Dim strRefName As String
        Dim ref As Access.Reference
        On Error GoTo AddRef_err
        
        Set ref = Application.References.AddFromFile(strRefPath)
        strRefName = ref.Name
        
      AddRef_exit:
        AddRef = strRefName
        Exit Function
      AddRef_err:
        MsgBox "AddRef error #" & Err & "--" & Err.Description
        Resume AddRef_exit
      End Function
      • #600159

        Thankyou both for your input. The addin I am referring to is LJHUtilities that include a reference to be set. As far as I know, these are only to help you write access, and are not needed to run, but because of the reference, the MDE’s break when distributed to other machines. My plan is to remove the references, make the mde and then reset the references. From both your inputs I have been able to do this. (I think, I’m still checking)

    Viewing 1 reply thread
    Reply To: Switch References on and off with code (Acc 97 sr2 on 95b)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: