Results 1 to 6 of 6
  1. #1
    Dan Hugos is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Location
    Jim Thorpe, PA
    Posts
    28

    Reference Removal, Get 'Subscript out of range.'

    Trying to remove a reference to a form object from an app. My code:



    Dim ref As Reference, strRef As String
    For Each ref In References

    If ref.FullPath Like "*" & "FM20" & "*" Then
    strRef = ref.FullPath
    GoTo DeleteIt
    End If

    Next ref

    DeleteIt:
    Set ref = References(strRef)
    References.Remove ref

    When it goes to set the reference, I can see that it's getting to the "Set ref = References(strRef)" statement, but then it breaks. I get "Subscript out of range." What am I missing?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    What is FM20? Is this supposed to be literal text and not a variable? Why use concatenation?

    If ref.FullPath Like "*FM20*" Then

    I don't understand what 'reference' you are removing.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    Dan Hugos is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Location
    Jim Thorpe, PA
    Posts
    28
    Yes, I'm looking for literal text that is a part of the Fullpath property of the Reference.

    For what it's worth, the reference is MS Forms 2.0, but the actual issue is why the code works fine until it gets to the line where it says 'Set Ref = References(strRef)' which is when it returns 'Subscript out of range.'

    This is even though Access set the strRef variable. Doesn't seem to make sense, so I'm guessing I'm missing something very obvious.

  4. #4
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,929
    I don't even see that library in the References list.

    I've never tried code to add or remove references. No idea why that fails.

    Does this help http://support.microsoft.com/en-us/kb/308340
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  5. #5
    Dan Hugos is offline Novice
    Windows 7 64bit Access 2010 64bit
    Join Date
    Mar 2015
    Location
    Jim Thorpe, PA
    Posts
    28
    Since it doesn't appear by default on your reference list, you have to browse to it. On an XP machine it's in Windows\System32, on a Win7 machine it's in Windows\SysWow64. It's called FM20.DLL. I'll have a look through the kb, thanks for pointing it out.

  6. #6
    ssanfu is offline Master of Nothing
    Windows XP Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    I found some code by Terry Kreft at http://bytes.com/topic/access/answer...references-vba
    and modified it to print to the immediate window.

    Code:
    Sub CheckReference()
        'Terry Kreft
        'http://bytes.com/topic/access/answers/210488-how-delete-missing-references-vba
    
        Dim refCurr As Access.Reference
        Dim intCount As Integer
        Dim strRef As String
        Dim bIsName As Boolean
    
        For intCount = Access.References.Count To 1 Step -1
            bIsName = False
            Set refCurr = Access.References(intCount)
            Debug.Print intCount & "  |  " & refCurr.BuiltIn & "  |  " & refCurr.Name & "  |  " & refCurr.FullPath
    
            'cannot remove built in references
            If Not refCurr.BuiltIn Then
    
                If refCurr.IsBroken Then
                    Access.References.Remove refCurr
                Else
                    'is this the one I want to delete?
                    bIsName = InStr(refCurr.FullPath, "FM20")
    
                    'could also use
                    '    bIsName = InStr(refCurr.Name, "MSFORMS")
    
                    If bIsName Then
                        Access.References.Remove refCurr
                        Debug.Print "***** reference to MS Form removed *******"
                    End If
                End If
            End If
        Next
    
    End Sub
    Tested in Win XP, Access 2010

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Sometimes get subscript out of range
    By khughes46 in forum Import/Export Data
    Replies: 8
    Last Post: 06-13-2014, 10:22 AM
  2. Subscript out of Range in Access 2010
    By jenngee in forum Import/Export Data
    Replies: 2
    Last Post: 11-26-2013, 10:30 AM
  3. subscript out of range
    By philfer in forum Access
    Replies: 3
    Last Post: 08-17-2013, 01:22 PM
  4. subscript out of range error
    By adray13 in forum Import/Export Data
    Replies: 4
    Last Post: 05-24-2013, 02:26 AM
  5. Subscript out of range (9)
    By msche398 in forum Programming
    Replies: 1
    Last Post: 07-08-2011, 12:52 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums