none
Error 91 for VBA

    Question

  • Hi all

    I am programming in VBA with ArcObjects. I got the error 91: Object Variable or With block variable not set . My code is as follows :

    *********************

    Dim pDispTab As IDisplayTable
    Dim pMXD As IMxDocument
    Dim pTable As ITable


    Set pMXD = ThisDocument
    Set pDispTab = pMXD.SelectedItem
    Set pTable = pDispTab.DisplayTable  ' --> showing error in this line

    Any kind of help will be appreciated. I am very new in this forum, if I have posted it in wrong place then please forward it to right place. :)

    Best regards,



    • Moved by Martin_Xie Wednesday, February 10, 2010 7:24 AM Move it to VBA Forum for better support. (From:Visual Basic Language)
    Tuesday, February 09, 2010 2:33 PM

Answers

  • Hi

    Sorry, the End if should be before the End Sub

    Public Sub CallculateXandYfields()
    
    Dim pDispTab As IDisplayTable
    Dim pMXD As IMxDocument
    Dim pTable As ITable
    Dim pCursor As ICursor
    Dim pRow As IRow
    Dim pPoint As IPoint
    
    Set pMXD = ThisDocument
    Set pDispTab = pMXD.SelectedItem
    
    If Not pDispTab Is Nothing Then
    
     Set pTable = pDispTab.DisplayTable  ' error 91 was here before  
    
    
    Set pCursor = pTable.Search(Nothing, False)    ' now error 91 is showing here 
    
    Set pRow = pCursor.NextRow
    
    Do While Not pRow Is Nothing
        'enter the name of the field below
       
        Set pPoint = pRow.Value(pTable.Fields.FindField("Shape"))
        If pPoint.IsEmpty = False Then
        
            pRow.Value(pTable.Fields.FindField("Ukoordx")) = pPoint.x
            pRow.Value(pTable.Fields.FindField("Ukoordy")) = pPoint.y
            pRow.Store
        End If
        
        Set pRow = pCursor.NextRow
    Loop
    
    End If ' If there is nothing in pDispTab the entire code below it will not be executed
    
    End Sub
    

    http://www.vbadud.blogspot.com
    • Marked as answer by Tim Li Friday, February 19, 2010 3:06 AM
    Saturday, February 13, 2010 8:07 AM

All replies

  • This error might occur if the object pDispTab doesn't hold anything:

    You can check that by

    Set pDispTab = pMXD.SelectedItem

    If Not pDispTab Is Nothing Then

     Set pTable = pDispTab.DisplayTable

    End if

    Cheers
    Shasur
    http://www.vbadud.blogspot.com
    Thursday, February 11, 2010 1:44 AM
  • Hi Shasur

    Thanks for your reply. I did what you said but I got the same error (error 91) in the next segment of the program. I am copping the whole function hare.

    ************************

    Public Sub CallculateXandYfields()

    Dim pDispTab As IDisplayTable
    Dim pMXD As IMxDocument
    Dim pTable As ITable
    Dim pCursor As ICursor
    Dim pRow As IRow
    Dim pPoint As IPoint

    Set pMXD = ThisDocument
    Set pDispTab = pMXD.SelectedItem

    If Not pDispTab Is Nothing Then

     Set pTable = pDispTab.DisplayTable  ' error 91 was here before 

    End If

    Set pCursor = pTable.Search(Nothing, False)    ' now error 91 is showing here

    Set pRow = pCursor.NextRow

    Do While Not pRow Is Nothing
        'enter the name of the field below
      
        Set pPoint = pRow.Value(pTable.Fields.FindField("Shape"))
        If pPoint.IsEmpty = False Then
       
            pRow.Value(pTable.Fields.FindField("Ukoordx")) = pPoint.x
            pRow.Value(pTable.Fields.FindField("Ukoordy")) = pPoint.y
            pRow.Store
        End If
       
        Set pRow = pCursor.NextRow
    Loop

    End Sub

    ***********************

    Please help me if you notice anything wrong in my code.
    Thanking you once again.
    Regards,





    Thursday, February 11, 2010 2:21 PM
  • Hi

    Sorry, the End if should be before the End Sub

    Public Sub CallculateXandYfields()
    
    Dim pDispTab As IDisplayTable
    Dim pMXD As IMxDocument
    Dim pTable As ITable
    Dim pCursor As ICursor
    Dim pRow As IRow
    Dim pPoint As IPoint
    
    Set pMXD = ThisDocument
    Set pDispTab = pMXD.SelectedItem
    
    If Not pDispTab Is Nothing Then
    
     Set pTable = pDispTab.DisplayTable  ' error 91 was here before  
    
    
    Set pCursor = pTable.Search(Nothing, False)    ' now error 91 is showing here 
    
    Set pRow = pCursor.NextRow
    
    Do While Not pRow Is Nothing
        'enter the name of the field below
       
        Set pPoint = pRow.Value(pTable.Fields.FindField("Shape"))
        If pPoint.IsEmpty = False Then
        
            pRow.Value(pTable.Fields.FindField("Ukoordx")) = pPoint.x
            pRow.Value(pTable.Fields.FindField("Ukoordy")) = pPoint.y
            pRow.Store
        End If
        
        Set pRow = pCursor.NextRow
    Loop
    
    End If ' If there is nothing in pDispTab the entire code below it will not be executed
    
    End Sub
    

    http://www.vbadud.blogspot.com
    • Marked as answer by Tim Li Friday, February 19, 2010 3:06 AM
    Saturday, February 13, 2010 8:07 AM