check if file already exists

Humberto

Registered User.
Local time
Today, 09:42
Joined
Jan 8, 2002
Messages
40
Hello, I'm running a report everyday when I open my project, the problem is that the project is opened more than once a day and I only want to run the report once a day. What I want to do is to check if the file already exist before running it again. can someone help me. All help will be appreciated.
 
Perhaps you could acchieve this by using the Dir() function?

Fuga.
 
Thank you for responding. I don't undestand what you mean about dir() function. I looked for this function but could not find anything. can you tell me how to implement the dir()funtion.

Thanks
 
Searching the help files for Dir will show you all the options and some examples for using the Dir function as Fuga suggested.

If Dir("X:\Data\Files\Test.doc") = "" Then
Msgbox "File does not exist"
Else
Msgbox "File exists"
End If

HTH
 
Hello, I was reading these posts as it was the closest to the issue I am having. I have an access application that is only to be used on certain PC's. Now every ime they open it up and import from a PC that isn't to be used they crash the database. Is there a way I can have the database check for the import file in C:\Windows\Import.csv before it opens the main form so that if the file isn't there the form doesn't open they get a message instead. If the file is there then the main form opens? Any help would be appreciated as I'm pulling my hair out on this one.
 
in the form_open event use the same idea

Code:
form_open event
    
if dir("yourfile")="" then
    msgbox ("file not available")
    cancel =true
    exit sub
end if

note that this will raise a 2501 error that you may have to error trap.
 
Hi Dave,

Thanks this worked out perfectly. Didn't come up with any errors that had to be trapped.

Cheers,
Rob
 
Dave I have another tricky one if your upto it lol
 
Thanks Dave,

I was able to muddle through it ang get it working without pulling any more hair out lol..
 
To add to Dave's advice you can add a flag to a file so that you know whether or not the file exists - it is just a visual aide:
Code:
if dir("yourfile")="" then
      Me.[File_Exist] = 0
else
      Me.[File_Exist] = -1
end if
exit sub

Simon
 
Hi Dave,


Here is a question on this. Is it possible to get access to check for a predetermined file on the internet and if it is there let the database open and if it isn't return a message like above?

So say this is where the file is ( called load.flag) Http:\mysite.com\project\load.flag I can get access to check for it. Or is that beyond what access can do?


Cheers,
Rob
 

Users who are viewing this thread

Back
Top Bottom