Closed Thread
Results 1 to 3 of 3

Error 91 object variable not set

  1. #1
    Forum Contributor
    Join Date
    02-13-2016
    Location
    CT USA
    MS-Off Ver
    office 365 subscription
    Posts
    180

    Error 91 object variable not set

    I am having a problem setting an object property which is itself an object.

    The error code (Error 91) suggests an object variable is not set. I know I have
    declared and assigned a valid reference to the object being stored and the object doing the storing.

    So I am wondering if the problem is that I do not understand object scope wherein maybe one of the objects loses scope.

    Any suggestions are appreciated.


    /code snippet
    ‘ for as many Measurements exist in FieldData
    With Ptr2OpnWrkBk
    With Ptr2FDWrkSht
    For Row = DataRowStart To NumofRows
    ' instantiate a Measurement Obj
    Set Ptr2FieldData = New MeasurementObj '
    ' instantiate a coordinates obj
    Set FieldDataCoordinates = New CoordinatesObj
    ' read MeasurementData into the MeasurementObj
    Ptr2FieldData.ID = Ptr2FDWrkSht.Cells(Row, ElevationIDColumn).value
    /code region of interest
    FieldDataCoordinates.X = Ptr2FDWrkSht.Cells(Row, X_CoordinateColumn).value
    FieldDataCoordinates.Y = Ptr2FDWrkSht.Cells(Row, Y_CoordinateColumn).value
    Ptr2FieldData.Coordinates = FieldDataCoordinates
    /end code region of interest
    Ptr2FieldData.Elevation = Ptr2FDWrkSht.Cells(Row, ElevationColumn).value
    Ptr2FieldData.ElevationType = Ptr2FDWrkSht.Cells(Row, ElevationTypeColumn).value
    ' add Ptr2FDo to FieldDataCollection
    Call Ptr2FDc.Add(Ptr2FieldData)
    Next
    End With
    End With
    /end code




    /code of MeasurementObj in which the instantiated object throws an error

    Option Explicit
    ' MeasurementObj

    Private PMeasurementID As Long
    Private PMeasurementElevation As Double
    Private PMeasurementElevationType As String
    Private PMeasurementCoordinates As CoordinatesObj



    Public Property Let ID(value As Long)
    PMeasurementID = value
    End Property
    Public Property Get ID() As Long
    ID = PMeasurementID
    End Property


    Public Property Let Elevation(value As Double)
    PMeasurementElevation = value
    End Property
    Public Property Get Elevation() As Double
    Elevation = PMeasurementElevation
    End Property


    Public Property Let ElevationType(value As String)
    PMeasurementElevationType = value
    End Property
    Public Property Get ElevationType() As String
    ElevationType = PMeasurementElevationType
    End Property

    /CODE IN WHICH ERROR OCCURS
    Public Property Let Coordinates(value As CoordinatesObj)
    PMeasurementCoordinates = value
    End Property
    /END CODE IN WHICH ERROR OCCURS

    /code continued
    Public Property Get Coordinates() As CoordinatesObj
    Coordinates = PMeasurementCoordinates
    End Property
    /end of code

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,644

    Re: Error 91 object variable not set

    Any chance you could upload a sample workbook?

    Click on GO ADVANCED, scroll down and click Manage Attachments.

    PS Can you please add code tags when posting code?
    If posting code please use code tags, see here.

  3. #3
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,809

    Re: Error 91 object variable not set

    Welcome to the Forum, unfortunately:

    This is a duplicate post and as such does not comply with Rule 5 of our forum rules. This thread will now be closed, you may continue in your other thread.

    Thread Closed.
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

Closed Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 7
    Last Post: 05-19-2016, 05:12 AM
  2. [SOLVED] Run-time error '91': Object variable or With block variable not set when closing userform
    By bishoposiris in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-10-2016, 08:59 AM
  3. Replies: 2
    Last Post: 08-22-2014, 03:55 AM
  4. [SOLVED] New Error/Old Code - Run Time Error 91; Object variable or With block variable not set
    By humboldtguy in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 02-15-2014, 12:39 AM
  5. Replies: 6
    Last Post: 12-21-2012, 08:03 AM
  6. Object variable or With block variable not set Error during sorting program
    By BlahBlahBlahBlahBlah in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-17-2012, 07:57 AM
  7. Object Variable Not Set Error on Selection object
    By Jean in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-24-2006, 01:50 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1