You could check the TypeName of MyFile:
If TypeName(MyFile) <> "Empty" Then
blah
End If
Alternatively, and probably best practice, would be to initialize the
MyFile object to Nothing when you declare it.
For example, wherever you Dim MyFile, instead do:
Dim myFile : Set myFile = Nothing
Aaron
On 11/26/2011 4:44 PM, David wrote:
In one of my apps, I am trying to figure a way to perform the
following; if such is possible, that is.
I have a FileSystemObject defined as FS. Then somewhere in the code, I
have a line like:
Set MyFile = FS.OpenTextFile( "test.txt", 1, False)
This to open a textfile object, in the Object MyFile.
A third place in the code, I want to check if the MyFile object is
active. If it is, I want to have it closed.
I tried this:
If Not MyFile Is Nothing Then MyFile.Close
This works in some cases, but other times I am getting an error
message, saying the object is undefined. Seems to me, if the object
has been in use once, it works, but not if there has been no call for
the object through the process.
OK, so my Question:
Is there any way for me, to check to see if an object has been
defined, and is active? Some way, that will not leave me with an error
message?
Thanks for any idea.
--
Aaron Smith
Web Development * App Development * Product Support Specialist
GW Micro, Inc. * 725 Airport North Office Park, Fort Wayne, IN 46825
260-489-3671 * gwmicro.com
To insure that you receive proper support, please include all past
correspondence (where applicable), and any relevant information
pertinent to your situation when submitting a problem report to the GW
Micro Technical Support Team.