[RESOLVED] correct usage of "Is Not Nothing"-VBForums
Results 1 to 11 of 11

Thread: [RESOLVED] correct usage of "Is Not Nothing"

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    May 2003
    Location
    USA, East Coast
    Posts
    257

    Resolved [RESOLVED] correct usage of "Is Not Nothing"

    What's the correct syntax/usage of this line:

    If frmForm1 Is Not Nothing Then ..etc.

    I keep getting "Invalid use of object" error.

    Really what I'm trying to say in code is:
    1)if frmForm1 is not unloaded yet then etc.. do stuff

    2)So if the Form is unloaded, don't do anything - skip the lines of code

    Thanks

  2. #2
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,716

    Re: correct usage of "Is Not Nothing"

    It's like this:

    If Not (frmForm1 Is Nothing) Then

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    36,798

    Re: correct usage of "Is Not Nothing"

    Just like it would be for an = rather than an 'Is', ie:
    Code:
    If Not frmForm1 Is Nothing Then
    ("Not" is effectively the same as "=False", so what you had was basically the same as: "If frmForm1 Is (Nothing=False) Then" )

  4. #4

    Thread Starter
    Hyperactive Member
    Join Date
    May 2003
    Location
    USA, East Coast
    Posts
    257

    Re: correct usage of "Is Not Nothing"

    Thanks Guys.

  5. #5
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,716

    Re: correct usage of "Is Not Nothing"

    If that does not work, then try this:
    Code:
    Public Function IsFormLoaded(FormName As String) As Boolean
        Dim Frm As Form
        
        For Each Frm In Forms
            If LCase(Frm.Name) = LCase(FormName) Then
                IsFormLoaded = True
                Exit Function
            End If
        Next Frm
    End Function
    
    If Not IsFormLoaded("frmForm1") Then ...
    I'm posting that because sometimes by just checking if the form is loaded you load the form
    So the function does not load the form un-intentionally

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    May 2003
    Location
    USA, East Coast
    Posts
    257

    Re: correct usage of "Is Not Nothing"

    Hey

    It does the code either way.

    I clearly: UnLoad Me (my splash page)

    but it is doing the code that should only execute when the Splash form is Loaded and Shown.

    thanks

  7. #7
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    36,798

    Re: [RESOLVED] correct usage of "Is Not Nothing"

    A form will automatically re-load itself if you run any code which refers to it (or the controls on it), or if it has a Timer control which you have not turned off.

    Note that generally you should have "Exit Sub" immediately after "Unload Me", and should always disable Timer controls in the _Unload event of the form.

  8. #8
    PowerPoster
    Join Date
    Oct 2002
    Location
    British Columbia
    Posts
    9,758

    Re: [RESOLVED] correct usage of "Is Not Nothing"

    The simple act of checking if a Form Is Nothing will Initialize (but not Load) the Form. If frmForm1 is the actual name of a Form then the statement If Not frmForm1 Is Nothing will always be True.

  9. #9

    Thread Starter
    Hyperactive Member
    Join Date
    May 2003
    Location
    USA, East Coast
    Posts
    257

    Re: [RESOLVED] correct usage of "Is Not Nothing"

    Si, you're absolutely right, I am running code which refers to the splash page.
    I did "Exit Sub" immediately after "Unload Me", and disabled the Timer and it is still displaying the Splash page after the app has started. I'll give CV's code a try and post back.

    CJ

  10. #10

    Thread Starter
    Hyperactive Member
    Join Date
    May 2003
    Location
    USA, East Coast
    Posts
    257

    Re: [RESOLVED] correct usage of "Is Not Nothing"

    None of it is working as expected. THanks , when I figure it out, I'll post for others.

    CJ

  11. #11

    Thread Starter
    Hyperactive Member
    Join Date
    May 2003
    Location
    USA, East Coast
    Posts
    257

    Re: [RESOLVED] correct usage of "Is Not Nothing"

    OK, somehow this works using the Function CV suggested:

    If IsFormLoaded("frmForm1") Then

    Happy Days
    CJ

Posting Permissions

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



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.