Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

FileExists question 2

Status
Not open for further replies.

marduk813

Programmer
Jul 18, 2002
89
US
I've got a userform set up to display a message if a particular file does not exist. The pathname and filename are stored in two different cells on my worksheet. When both the correct pathname and correct filename are present, FileExists returns True (as expected), however, even when I delete the pathname cell, FileExists still returns True. The filename does not exist in the same folder as my source/current file, so I'm not sure how it's locating it.

Any ideas why it's not returning False?
 
What is FileExists ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
The FileExists method. From the VBA help file:

Description

Returns True if a specified file exists; False if it does not.

Syntax

object.FileExists(filespec)

The FileExists method syntax has these parts:

Part Description
object Required. Always the name of a FileSystemObject.
filespec Required. The name of the file whose existence is to be determined. A complete path specification (either absolute or relative) must be provided if the file isn't expected to exist in the current folder.
 
I'd have to see your code to ensure that it's working alright. Try using the Dir() function though. It will return a null string if the file doesn't exist. Plus it doesn't need the Scripting Object like your function does.

HTH

Regards,
Zack Barresse

Simplicity is the ultimate sophistication. What is a MS MVP? PODA
- Leonardo da Vinci
 
firefytr,

Using Dir() seems to have worked. I'm still not sure what was causing the problem with FileExists, but since this is working, I'm not going to worry about it. Now I just have to figure out how to get an event to run periodically on the form. Like a refresh event or something.

Thanks!
 
Have a look at the Application.OnTime method.

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
PH,

That would work, except that I need something for a userform. I'm not sure where I could put the Application.OnTime method and have it constantly running while the userform is being used. I may not have been very clear earlier about what I needed. While the userform is loaded and visible, I need to check the values of two cells on the worksheet behind it. The only way those cells can change value is from user input on a 2nd userform. What I was trying to do was have some sort of timed event or refresh event for the first userform (Main).

In other words, user clicks buttonSub on formMain, and it opens formSub. Once they're done with formSub (in which they can modify two cell values), they click a close button which brings them back to formMain. At that point, I need to have formMain examine the values of two cells to see if they've changed. And that's where I'm stumped. I don't know what event I can fire to have it check those values. I've tried UserForm_Activate, but it doesn't seem to do it.
 
If formSub is modal then simply do your check just after opening it ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Or...don't use a second userform. You could use a MultiPage, or resize the userform to show new space (and controls) for the data change for those cells. The user clicks an OK button for that change - the userform resizes back and updates.

Gerry
My paintings and sculpture
 
Well, formSub was modal, but I couldn't get it to call the particular sub when I closed formSub, but that was because the code was in the Open event of formMain. I moved all the code to a module and just directed all my calls to there. That took care of it. Thanks for the help PH!


Jas
 
Or store previous values somewhere, memory, temporary cell/object, etc, check against each other. I would be using some kind of public variable probably, or dictionary object.

Regards,
Zack Barresse

Simplicity is the ultimate sophistication. What is a MS MVP? PODA
- Leonardo da Vinci
 
Hi everyone,

I noticed that you're testing for file existence with Dir. If you decide to get into testing directories with Dir for any reason, just be aware that it won't return true if there is no FILE in the directory (even if there are subdirectories.)

I created a function to test if a file or directory exists at my site, and the article covers the Dir issue in it's preface:

Ken Puls, CMA
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top