Results 1 to 4 of 4
  1. #1
    3 Star Lounger
    Join Date
    Nov 2001
    Location
    Brisbane, Queensland, Australia
    Posts
    330
    Thanks
    10
    Thanked 0 Times in 0 Posts

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

    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.
    "Heading for the deep end"

  2. #2
    Star Lounger
    Join Date
    Nov 2001
    Location
    Illinois, USA
    Posts
    60
    Thanks
    0
    Thanked 0 Times in 0 Posts

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

    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

  3. #3
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

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

    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.
    <pre>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</pre>


    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.
    <pre>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</pre>


    And finally, heres a routine to add a reference:
    <pre>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</pre>

    Charlotte

  4. #4
    3 Star Lounger
    Join Date
    Nov 2001
    Location
    Brisbane, Queensland, Australia
    Posts
    330
    Thanks
    10
    Thanked 0 Times in 0 Posts

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

    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)
    "Heading for the deep end"

Posting Permissions

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