473,320 Members | 2,041 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Checking for an application in Code - URGENT

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
8 1398
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
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
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


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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: HIK | last post by:
Click once can be set up to pole the setup url if there is a newer version or not. I have a project which can only be deployed using a setup project. How can I create the same feature in my setup...
4
by: Jeff | last post by:
I have a vb.net application (2005) requiring session variables and want to test to make certain that the user's cookies are enabled. I can set a test session variable on one page and attempt to...
7
by: =?Utf-8?B?Q2hyaXMgQ2Fw?= | last post by:
We are considering moving from using several seperate webservers to a web farm. I was lookingg at implementing a start server to manage state for the web farm. The problem is, how do we keep...
15
by: =?Utf-8?B?TVNU?= | last post by:
To demonstrate my problem, I have a very simple VB Windows application. It has a text box that is used to display a counter, a button to reset the counter, and a timer that increments the counter...
125
by: jacob navia | last post by:
We hear very often in this discussion group that bounds checking, or safety tests are too expensive to be used in C. Several researchers of UCSD have published an interesting paper about this...
5
by: J055 | last post by:
Hi The following code works on my develeopment machine using the VS web server. When I run the application on 2 other Windows 2003/IIS 6 servers no caching seems to take place at all. Can...
1
by: sruthini | last post by:
Hi, I am trying to checking the size of a file using javascript, I am using the following code <html> <head> <script language="JavaScript"> function A() { var oas = new...
1
by: yoavyoavyoav | last post by:
Hi There , I have an application that uses excel COM interop. (Microsoft.Office.Interop.Excel) However , If i distribute my app to computers that for eg. do not have excel , The application...
3
by: =?Utf-8?B?RVF1QWw=?= | last post by:
Hi, We have an application developed in VC2005 with mixed code, primarily C++ but using a C# dll for database access (DBUploader), the dll exposes a C++ interface. We are experiencing...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.