Results 1 to 6 of 6

Thread: Object reference not set to an instance of an object

  1. #1

    Thread Starter
    Addicted Member ProgrammerJon's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    203

    Object reference not set to an instance of an object

    Why would I get this error, and how can I stop my program from getting it?
    Object reference not set to an instance of an object.

    I often get when trying to change the value of a variable.

    ex.
    [Add MS Outlook Reference]
    Code:
    Imports Office
    .
    .
    .
    Sub SearchHD
    Dim Search as Office.FileSearch
    Search.FileName = "test" 'I get the Error Here
    End Sub

  2. #2
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Because you are trying to use a null object reference. You need to create the object using the new construct:

    Code:
    Dim Search as New Office.FileSearch()
    
    ' or...
    Dim Search as Office.FileSearch
    Search = New Office.FileSearch()
    Last edited by Lethal; Mar 5th, 2003 at 08:44 PM.

  3. #3

    Thread Starter
    Addicted Member ProgrammerJon's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    203
    Originally posted by Lethal
    Because you are trying to use a null object reference. You need to create the object using the new construct:

    Code:
    Dim Search as New Office.FileSearch()
    
    ' or...
    Dim Search as Office.FileSearch
    Search = New Office.FileSearch()
    That dosn't work because "New Office.FileSearch" dosn't exsist.

  4. #4
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    If there is no public New then that usually means that you cannot create the object in that manner. This is an intentional thing the same as a PublicNotCreatable class in VB6. Generally that means that another object or method returns the one in question (FileSearch) and that is the only way you are suppose to be getting one.

  5. #5

    Thread Starter
    Addicted Member ProgrammerJon's Avatar
    Join Date
    Jan 2003
    Location
    Canada
    Posts
    203
    So how would I use the FileSearch Property then?

  6. #6
    Your Ad Here! Edneeis's Avatar
    Join Date
    Feb 2000
    Location
    Moreno Valley, CA (SoCal)
    Posts
    7,339
    I'm not sure, try selecting it and pressing F1 for help. I believe its a class not really a property and I'd imagine that there is another class and/or method that would ahve the return value of type FileSearch and that is how you get it. But I've never used that particular object so I don't know which one that would be.

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