>>>>>>Using vfp6.0
>>>>>>
>>>>>>I have a program that creates a .dbf file (fox2 format) to be used by MS Word for mail merge. Everytime a user creates labels, it also issues a 'copy to myMrgFile type fox2'. My .exe file never opens the file. But --- heres a scenerio I am expecting:
>>>>>>
>>>>>>1) User has my .exe and MS Word open.
>>>>>>2) User is in the middle of a mail merge and notices names are missing.
>>>>>>3) User switches to my vfp .exe and pulls another query.
>>>>>>4) Vfp .exe file attempts to 'copy to myMrgFile type fox2' but since Word has it open - it fails.
>>>>>>
>>>>>>I am dealing with very elderly people, most of which do not know how to use mail merges. I don't want to use a putfile().
>>>>>>
>>>>>>Question:
>>>>>>How can I find out if myMrgFile.dbf is open by another program (not necessarily Word)?
>>>>>>
>>>>>>Robert
>>>>>
function inuse
>>>>>lparameters cfilename
>>>>>handle=fopen(cfilename)
>>>>>if handle>0
>>>>> =fclose(handle)
>>>>> return .f.
>>>>>endif
Cetin
>>>>
>>>>
>>>>Cetin,
>>>>This worked great. Thanks.
>>>>
>>>>Robert
>>>
>>>Hello Robert,
>>>
>>> Though Cetin is right but it would be better to find out what caused FOPEN() to return -1. I mean error could be something else. I sugget you to use FERROR() function to determine exact error. It this error is 'File Access Denied'. then do whatever you want to do.
>>>
>>>Bye
>>>Jayesh
>>
>>Jayesh,
>>
>>I just looked up ferror() and you are correct, If a user deleted the file, then I could simply recreate it. There are other issues to look at, but that is a good point. Thanks.
>>
>>Robert
>Robert,
>I confess it was a quick, careless reply and I really expected this "if file is deleted, doesn't exist", then simply change fopen to fcreate. Ferror while a good programming habbit may become just extra coding though (if only for this purpose).
>Instead "error trapping + use" as Ed suggested is better.
>Cetin
Cetin,
Actually, I thought Word would read a old fox dbf file and when I tried to mail merge it, I found out it doesn't support it. I then changed the file I am checking for to a excel file format, therefore your fopen() example works fine. I'll incorporate the ferror() into it though.
Robert