By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,704 Members | 1,861 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,704 IT Pros & Developers. It's quick & easy.

Checking for an application in Code - URGENT

P: n/a
I was wondering if I can check to see if a file is open?

Specifically, is there any way I can code Access to check to see if a
text file (datasource.txt to be specific) is open, returning a true
value and creating a loop? Then, once the file closes, return a false
value and closing the loop?

I need to run a batch file using Shell() and then run queries based on
the text files that this batch files create. The catch is that the
batch file calls a proprietary file transfer that keeps running well
after the batch file closes. This file transfer writes its results to
the text file above, which is why i am interested in seeing if it is
open or not, and then continuing a loop if it is not.

Since my job is on the line for this one, I would REALLY apreciate any
help I can find.
Nov 12 '05 #1
Share this Question
Share on Google+
8 Replies


P: n/a
On 23 Feb 2004 14:38:10 -0800, gremlinbass wrote:
I was wondering if I can check to see if a file is open?

Specifically, is there any way I can code Access to check to see if a
text file (datasource.txt to be specific) is open, returning a true
value and creating a loop? Then, once the file closes, return a false
value and closing the loop?

I need to run a batch file using Shell() and then run queries based on
the text files that this batch files create. The catch is that the
batch file calls a proprietary file transfer that keeps running well
after the batch file closes. This file transfer writes its results to
the text file above, which is why i am interested in seeing if it is
open or not, and then continuing a loop if it is not.

Since my job is on the line for this one, I would REALLY apreciate any
help I can find.


Not really sure what to do about the loop. Having a loop like this could
become a problem if the file never released. You may want to include a
counter and limit the "polling" to a maximum (time or loops).
As for checking the file, if the file transfer opens or creates the file
and locks it, then you could probably use the Open statement to try and
open the file for read/write.
If the file is already locked, then Open will cause an error. You could
probably use a Do While Err <> 0 to run the loop until either the counter
runs out, or an error is no longer generated.
--
Mike Storr
www.veraccess.com
Nov 12 '05 #2

P: n/a
On 23 Feb 2004 14:38:10 -0800, db*******@yahoo.com (gremlinbass)
wrote:

You can test if a file is open by trying to open it exclusively. Check
the help page on the Open statement.
If you use an error handler, even as simple as:
On Error Resume Next
then you can test if the Open worked:
If Err.Number = 0 Then
Close <filenumber> ' Close the file you've just managed to open
exclusively.
blnTheFileIsNowAvailable = True
Else
blnTheFileIsNowAvailable = False
End If

Put all of this code in a function, and call it in a loop, where you
also add:
DoEvents ' Allow other processes to run
or, if you want to get creative, look for help online on the Sleep
API.

The function would return the value of blnTheFileIsNowAvailable so you
know when you can fall out of your loop.

-Tom.

I was wondering if I can check to see if a file is open?

Specifically, is there any way I can code Access to check to see if a
text file (datasource.txt to be specific) is open, returning a true
value and creating a loop? Then, once the file closes, return a false
value and closing the loop?

I need to run a batch file using Shell() and then run queries based on
the text files that this batch files create. The catch is that the
batch file calls a proprietary file transfer that keeps running well
after the batch file closes. This file transfer writes its results to
the text file above, which is why i am interested in seeing if it is
open or not, and then continuing a loop if it is not.

Since my job is on the line for this one, I would REALLY apreciate any
help I can find.


Nov 12 '05 #3

P: n/a
Go to www.MVPS.Org/Access. There's a ShellWait routine there where the code
waits until the Shelled file is complete. Sounds like this is what you need!
--
PC Datasheet
Your Resource For Help With Access, Excel And Word Applications
re******@pcdatasheet.com
www.pcdatasheet.com
"gremlinbass" <db*******@yahoo.com> wrote in message
news:31**************************@posting.google.c om...
I was wondering if I can check to see if a file is open?

Specifically, is there any way I can code Access to check to see if a
text file (datasource.txt to be specific) is open, returning a true
value and creating a loop? Then, once the file closes, return a false
value and closing the loop?

I need to run a batch file using Shell() and then run queries based on
the text files that this batch files create. The catch is that the
batch file calls a proprietary file transfer that keeps running well
after the batch file closes. This file transfer writes its results to
the text file above, which is why i am interested in seeing if it is
open or not, and then continuing a loop if it is not.

Since my job is on the line for this one, I would REALLY apreciate any
help I can find.

Nov 12 '05 #4

P: n/a


Thanks for the REALLY quick reply. I think that might work. Since I am
REALLY not programmer-savvy, do you think you could include an example
of what that code might look like?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #5

P: n/a
Thanks for the quick reply!

I really like the solution you presented. You mentioned filenumber
rather than filename. How does filenumber work and how would I find
that info out?

Thanks from the bottom of my feet!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #6

P: n/a
Thanks for replying so quickly!

I looked at the Shell Wait API and it does well to set a timer, but only
bases it on completing a shell() command. My problem is that the actual
batch file that I shell contains a single START command for a
proprietary process. The batch file itself is over and done with in a
matter of seconds...but the proprietary process is the one that takes so
long. It is because of this that the Shell Wait API only saves me about
a second or two before the whole thing comes crashing down.

I do really appreciate you finding that site for me though.

Thanks from the bottom of my feet!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 12 '05 #7

P: n/a
On 24 Feb 2004 15:18:27 GMT, Dustin Bailey wrote:
Thanks for the REALLY quick reply. I think that might work. Since I am
REALLY not programmer-savvy, do you think you could include an example
of what that code might look like?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


An alternative could be to modify the following to remove the loop, and
create a form and apply this code to it's timer event. This might be better
than using a loop. Also note that more error checking may be need depending
on what else is going on, before and after.

Function IsFileOpen(strFilePath As String, NumAttempts As Long) As Boolean
IsFileOpen = False

Dim fileHandle As Integer
Dim cntr As Long

For cntr = 0 To NumAttempts
fileHandle = FreeFile
Open strFilePath For Random Access Read Write Lock Read Write As
#fileHandle
If Err <> 0 Then
IsFileOpen = True
Exit Function
End If
Next cntr

MsgBox "Cannot open the specified file within the specified number of
attempts."

End Function
--
Mike Storr
www.veraccess.com
Nov 12 '05 #8

P: n/a
On 24 Feb 2004 15:18:27 GMT, Dustin Bailey <db*******@yahoo.com>
wrote:

Look up the Close statement in the Help file. You'll find that it
takes a filenumber argument (to close that specific file).

The filenumber typically is created by calling FreeFile.

-Tom.
Thanks for the quick reply!

I really like the solution you presented. You mentioned filenumber
rather than filename. How does filenumber work and how would I find
that info out?

Thanks from the bottom of my feet!

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 12 '05 #9

This discussion thread is closed

Replies have been disabled for this discussion.