Results 1 to 12 of 12

Thread: What the heck does "Object variable or With block variable not set" mean???

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2000
    Posts
    1,195
    I keep getting this runtime error 91..

    "Object variable or With block variable not set"

    what does it mean?

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    with what are you getting it, a variable, or control, or what?
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3
    PowerPoster
    Join Date
    Jul 1999
    Posts
    5,923
    I usually get that when i haven't set a variable with the Set keyword. For example the DataSource for many controls has to be done like so;
    Code:
    Set Moo.DataSource = Whatever
    If you just put
    Code:
    Moo.DataSource = Whatever
    it moans with that error.

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Dec 2000
    Posts
    1,195
    heres my code:

    Code:
    If TypeOf p_CurControl Is ListView Then
        '
        'if active control is listview
        '
        If p_CurItem.Icon = 4 Then
            '
            'If selected item is folder
            '
          
            GetSelectedPath = p_CurNode.Key & "\" & Right$(p_CurItem.Text, Len(p_CurItem.Text) - 1)
        Else
            '
            'if selected item is shortcut
            '
            GetSelectedPath = p_CurNode.Key & "\" & p_CurItem.Text
        End If
    Else
        '
        'If active control is treeview
        '
        GetSelectedPath = p_CurNode.Key
    End If
    I get the error at GetSelectedPath = p_CurNode.Key & "\" & p_CurItem.Text

    if i try msgbox p_curnode.key, i still get the same error.. This isnt my code, im just messin with someone elses

  5. #5
    Addicted Member dmr's Avatar
    Join Date
    Jul 2000
    Location
    West-Germany :) Timezone: GMT +1 [DST] North.......: 52° 16’ 09” East...: 10° 31’ 16”
    Posts
    255
    This means that you have created a variable that refers to an object, that doesn't exist...

    For example:

    Code:
       Dim fnt As StdFont
    
    Private Sub Form_Load()
       Set fnt = New StdFont  'When you leave this line, vb tries to do the next line with 'Nothing'
       fnt.Name = "Arial"
    
    End Sub
    Code that I author is neither elegant nor efficient. It is, however, functional. Once I get something that works, I'm generally satisfied with myself - I mean, if it works, that's good enough, right?

    Originally posted by aknisely
    Sorry, but I feel uncomfortable on CC with clothes on
    __________________
    The truth ... is out there!

  6. #6
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    You get this if you try to use a variable, but haven't told VB what the variables equal to :
    Code:
    Dim AString as String
    
    AString = "Hello World"
    MsgBox AString
    Will work, but in the below, I've just declared the variable, & not set a value to it so VB doesn't know what on earth tho return
    (and sorry for using a Hello World example ) :
    Code:
    Dim AString as String
    
    MsgBox AString
    Last edited by alex_read; Apr 9th, 2001 at 05:36 AM.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  7. #7
    Addicted Member
    Join Date
    Oct 2000
    Location
    Vienna/Austria
    Posts
    132
    Hi toghether !!!

    Sorry for my dump question, do you have compiled your project ?

    Because this error message happend often to me, if I forgot an "endif, ....", in a with statement.

    Note; the rror must not be in the same module

    -cu TheOnly

  8. #8
    Hyperactive Member Paul Warren's Avatar
    Join Date
    Jun 2000
    Location
    UK
    Posts
    282
    Actually Alex your answer will work, assuming the declaration is a typo ( you missed the 'r' in string). A string is initialised to "" when it's declared so you can use it, it'll just be blank. The error we're talking about here is specific to an object. That's because an object is just a pointer to a block of memory but if it's not set then it literally points at nothing and VB doesn't know what to do. Hence this error. TheOnly's example illustrates the other time you will get this message.

    Sooo, one of the objects in the original code must not be set. See my earlier reply to see how to check this out.

    Sorry to be a smart arse but I thought you might like to know the above.

    Anti-smartie pants note : All variables are actually pointers to a bit of memory where the value is held BUT VB does not initialise an object's memory space for you.
    Last edited by Paul Warren; Apr 9th, 2001 at 05:30 AM.
    That's Mr Mullet to you, you mulletless wonder.

  9. #9
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538

    Point taken, didn't test this one anyway.
    with my posts, you can guarantee it's always a typo & I constantly go back into my posts to change words - this is ammended!

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  10. #10
    Randalf the Red honeybee's Avatar
    Join Date
    Jun 2000
    Location
    off others' brains
    Posts
    4,345

    Well ...

    Originally posted by alex_read

    Point taken, didn't test this one anyway.
    with my posts, you can guarantee it's always a typo & I constantly go back into my posts to change words - this is ammended!
    Is that why your post count is that big??

    j/k

    .
    I am not a complete idiot. Some parts are still missing.
    Check out the rtf-help tutorial
    General VB Faq Thread
    Change is the only constant thing. I have not changed my signature in a long while and now it has started to stink!
    Get more power for your floppy disks. ; View honeybee's Elite Club:
    Use meaningfull thread titles. And add "[Resolved]" in the thread title when you have got a satisfactory response.
    And if that response was mine, please think about giving me a rep. I like to collect them!

  11. #11
    Evil Genius alex_read's Avatar
    Join Date
    May 2000
    Location
    Espoo, Finland
    Posts
    5,538
    Nah, these ones I'm talking about is me going into the already posted answers & ammending them.

    Please rate this post if it was useful for you!
    Please try to search before creating a new post,
    Please format code using [ code ][ /code ], and
    Post sample code, error details & problem details

  12. #12
    Hyperactive Member Paul Warren's Avatar
    Join Date
    Jun 2000
    Location
    UK
    Posts
    282
    Yeah, but RDO stands for Remote Data Objects. + 1
    That's Mr Mullet to you, you mulletless wonder.

Posting Permissions

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



Click Here to Expand Forum to Full Width