Results 1 to 5 of 5
  1. #1
    Join Date
    Nov 2002
    Location
    Belgium
    Posts
    243

    Unanswered: Error when loading references from file

    Hi,

    I want to load some references by using VBA.
    First I want to check if reference is already loaded.
    If yes I don't do anything, if no, reference needs to be loaded.

    I used following code :

    Private Sub LoadReference(pReference As String)
    If References(pReference).IsBroken Then
    References.AddFromFile (pReference)
    Else
    'do nothing
    End If
    End Sub


    But when I run the code I get an error saying : 'subscript out of range' on the line 'If References(pReference).IsBroken '


    Any help woud be appreciated.

    Thnaks

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    The IsBroken tests whether or not an added reference is... broken; it does not check for it's existence; hence why it fails when you're looking for one that's not added.

    Sadly, the only method I have found is to use an error handler to trap the error "reference already exists" when adding a reference. This can be found in this example.
    George
    Home | Blog

  3. #3
    Join Date
    Nov 2002
    Location
    Belgium
    Posts
    243
    Hello,

    Thanks for your reply georgev.
    I too a closer look at your example and used it in mine.
    However, when reference already exists it raises the error, but does not pass it to my errorhandler.

    I have no idea why it does not catch the error.
    Here's my code :

    ===============
    Private Sub LoadReferenceFromFile(pReference As String)

    On Error GoTo ErrorHandling

    References.AddFromFile (pReference)

    Exit Sub

    ErrorHandling:
    Select Case Err.Number
    Case 32813: 'Reference already loaded
    Resume Next
    Case Else:
    MsgBox Err.Number & vbCrLf & Err.Description, vbOKOnly, "ERROR"
    End Select

    End Sub
    ===============

    Thanks

  4. #4
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    i'm not a fan of addfromfile: locations change from version to version

    here is something similar using a different logic in the error trap, addfromguid, and 0,0 magic from occasional forum contributor Wayne Phillips.

    izy
    Attached Files Attached Files
    currently using SS 2008R2

  5. #5
    Join Date
    Dec 2002
    Location
    Préverenges, Switzerland
    Posts
    3,740
    Ahhh!

    so sorry George - didn't realise yours was also addfromguid until i took a peek.

    after OP came back again with the addfromfile distraction i made a foolish assumption. good to see you using 0,0 too.

    anyhoo, mine adds the broken check and takes a different road, so wasn't a complete waste of time.

    izy
    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
  •