Try Use (pcFileName) In 0 Alias Crime Exclusive Catch to oError EndTry If Vartype(oError) = "O" *-- An error occured. oError.ErrorNo contains error code, oError.Message contains error message *-- Do whatever you need to do here. Else Index On CrimeDate Tag CrimeDate *-- There is no need to set order to the tag - Index On automatically sets the order to it. EndIfSecond would be to intercept the error in Error method of the class/form - the object where this code is located. This apply only if you have this code in a class/form - not applicabile to a PRG procedure file:
Use (pcFileName) In 0 Alias Crime Exclusive If ThisForm.lErrorOccured *-- Do whatever you need to do in case of error Else *-- same code as ELSE above EndIfError method of the class where above code is located:
LParameters nError, cMethod, nLine *-- Show the error message to user, then set the error flag: ThisForm.lErrorOccured = .T. ReturnNext way would be to not rely on error routines at all; instead, try to open file exclusively:
lnFileHandle = FOpen(&pcFileName, 2) If lnFileHandle = -1 && it was opened - no one is using it, even shared FClose(lnFileHandle) Use (pcFileName) In 0 Exclusive Alias Crime Index On CrimeDate Tag CrimeDate Else *-- It is open. Show a suggestive message to user and return to GetFile() routine EndIfMost probably there are some other ways as well, however, 3 of them should be enough :)
>pcFileName = "" >pcFileName = Getfile('DBF') > >Select 0 && Selects the first available work area >Use (pcFileName) Alias crime Exclusive >Select crime > >Index On crimedate Tag crimedate && Thanks Sergey >* Set order to that TAG >Set Order To crimedate >