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

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
    Share on Google+

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

    Re: correct usage of "Is Not Nothing"

    It's like this:

    If Not (frmForm1 Is Nothing) Then
    Share on Google+

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

    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" )
    Share on Google+

  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.
    Share on Google+

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

    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
    Share on Google+

  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
    Share on Google+

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

    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.
    Share on Google+

  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.
    Share on Google+

  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
    Share on Google+

  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
    Share on Google+

  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
    Share on Google+

  12. #12
    New Member
    Join Date
    Feb 2016
    Posts
    2

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

    Hello everyone!
    I have a problem with VBA for Excel .
    I want to search for a specific value(for a specific ID) in a column of a sheet and pass the value in another table row (of that ID).
    What happens If the value in the What:="value" parameter of the Find() method doesn't exists for all the IDs in the column?
    If the ID (of the first sheet) doesn't have that value I dont want to pass any value to the other sheet (of that ID).I want to set a "#N/A" value instead
    In fact it passes the value of the predecessor ID.
    What should I do.
    Share on Google+

  13. #13
    Super Moderator FunkyDexter's Avatar
    Join Date
    Apr 2005
    Location
    An obscure body in the SK system. The inhabitants call it Earth
    Posts
    6,125

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

    You've asked your question in 7 year old thread that has nothing to do with your question and is in the VB6 section when your question is about VBA.

    Might I suggest that posting your question in a new thread, with an appropriate title, in the correct forum (which would be Office Development in this case) is likely to get you a better response.

    In the meantime I'll close this thread so that it can sink back into the murky depths from which it has been roused.
    When one of my minions says, "Hey, he's just one guy, what can he do?" I say "This"... and shoot them.

    The problem with putting your lair in a volcano is keeping your robot army from melting.

    I know that the human being and the fish can coexist peacefully - George Bush

    Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd
    Share on Google+

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.