Results 1 to 4 of 4

Thread: How to determine if object has been set

  1. #1

    Thread Starter
    Hyperactive Member Ed Lampman's Avatar
    Join Date
    Mar 2001
    Posts
    273

    How to determine if object has been set

    I know I've seen this here before, but how can I determine if an object has been set or not, to avoid Error 91?

    I've tried IsNull, = Nothing, etc but they don't work

    I need something like:

    (form level code)
    Private oMyObject as CMyObject

    Private Sub DoSomething()

    If oMyObject (doesnt yet exist) Then Set oMyObject = New CMyObject

    ....

    End Sub

  2. #2
    Hyperactive Member
    Join Date
    May 2000
    Location
    Or
    Posts
    316
    Try the IsEmpty command. It returns true if the variable is empty:

    VB Code:
    1. Private Sub Command1_Click()
    2. Dim ie As Object
    3.  
    4. If IsEmpty(ie) = True Then
    5.     ie.Visible = True
    6. Else
    7.     MsgBox "called"
    8.     Set ie = CreateObject("InternetExplorer.Application")
    9.     ie.Visible = True
    10. End If
    11.  
    12. End Sub

    Hope this helps.

  3. #3
    gaffa
    Guest
    I've alsways used Is Nothing:

    Code:
    If lobjObject Is Nothing then
        Set lobjObject = new DummyObject
    End iF
    - gaffa

  4. #4

    Thread Starter
    Hyperactive Member Ed Lampman's Avatar
    Join Date
    Mar 2001
    Posts
    273

    Thanks to Gaffa and Reeset

    Thanks!!

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