[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
Re: correct usage of "Is Not Nothing"
It's like this:
If Not (frmForm1 Is Nothing) Then
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" )
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
Re: correct usage of "Is Not Nothing"
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
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.
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.
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
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
Re: [RESOLVED] correct usage of "Is Not Nothing"
OK, somehow this works using the Function CV suggested:
If IsFormLoaded("frmForm1") Then
Happy Days
CJ
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.
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.