Sometimes it is necessary to do a little system maintenance. Sometimes the middle of the night just doesnt cut it. If you want to do and index and pack in your code, you should verify that you can use the tables exclusivly. <br>
Here is an example of such code.<br>
<br>
* Create an array of all tables in the database and scan them<br>
FOR i = 1 TO 3<br>
IF !EMPTY(latables<i>)<br>
ls_retry = "RETRY"<br>
ls_table = latables<i><br>
IF !lb_quit_program<br>
DO WHILE ls_retry = "RETRY"<br>
* If the file exists, check it by opening it<br>
IF FILE("data\"+ls_table+".dbf"

<br>
* Open the next table<br>
IF used(ls_table)<br>
USE IN (ls_table)<br>
ENDIF<br>
USE (ls_table) IN 0 EXCL && set_buf_optimistic takes care of this<br>
IF !CURSORSETPROP("BUFFERING",1,ls_table)<br>
lb_quit_program = .T.<br>
EXIT<br>
ENDIF<br>
IF USED(ls_table)<br>
* If the table is used, it is ok. Close it and try the next table.<br>
USE IN (ls_table) && new ah 9/23<br>
USE<br>
ls_retry = "OK"<br>
ELSE<br>
* If the table is not used, it had a problem. If retry is false, do not continue.<br>
IF ls_retry = "QUIT"<br>
lb_quit_program = .T.<br>
ENDIF<br>
ENDIF<br>
ELSE<br>
* If the file does not exist, an update is needed<br>
WAIT window "no file found"<br>
gb_update_needed = .T.<br>
ls_retry = "OK"<br>
ENDIF<br>
ENDDO<br>
ON ERROR<br>
IF lb_quit_program<br>
EXIT<br>
ENDIF<br>
ENDIF<br>
ENDIF<br>
ENDFOR<br>
<br>
SET EXCLUSIVE OFF<br>
IF lb_quit_program<br>
=messagebox("Unable to gain sole access to tables, process aborted.",48+0,"exclusive access denied"

<br>
ENDIF<br>
RETURN !lb_quit_program<br>
ENDFUNC