excuse me, but I am copy/paste the "whole" coding here, just look at it, if you find something could be improved or should be whatever, let me know...
CLEAR
SET MULTILOCKS ON
leavenow=.F.
SET ESCAPE OFF
ON ERROR DO getout
LOCAL laTables, lcTableName, lcKey
OPEN DATABASE po EXCLUSIVE
DIMENSION laTables[1]
ADBOBJECTS(laTables, "TABLE")
FOR EACH lcTableName IN laTables
USE (lcTableName) EXCLUSIVE IN 0
IF leavenow=.T.
EXIT
ENDIF
SELECT (lcTableName)
lcKey=TAG(1)
SET ORDER TO &lcKey
ENDFOR
IF leavenow=.T.
RETURN
ENDIF
SET ESCAPE ON
ON ERROR
*the remaining of the program starts right here...
SELECT poencr
APPEND FROM poencr.xls TYPE XLS
GO TOP
DELETE
PACK
SELECT workpo
APPEND FROM poencr
GO TOP
DO WHILE NOT EOF()
varpo = po
varclass = class
varfund = fund
varudds = udds
varamount = amount
varfy = fy
varactivity = activity
varaccount = account
SELECT histpo
SEEK varpo
IF FOUND()
IF class = varclass AND fund = varfund AND udds = varudds AND ;
amount = varamount AND fy = varfy AND activity = varactivity AND ;
account = varaccount
SELECT workpo
REPLACE code WITH "2"
ELSE
SELECT workpo
REPLACE code WITH "3"
ENDIF
ELSE
SELECT workpo
REPLACE code WITH "1"
ENDIF
SKIP
ENDDO
*****************************
*** HERE IS THE PROBLEM *****
*****************************
SELECT histpo
APPEND FROM workpo FOR ALLTRIM(workpo.code) = "1"
SELECT delepo
APPEND FROM workpo FOR ALLTRIM(workpo.code) = "3"
REPLACE deleted with DATE() for deleted = {}
*FLUSH <-- didn't work, as suggested, same with ALLTRIM either as above
RETURN
PROCEDURE getout
CLOSE ALL
WAIT WINDOW "The table(s) can not be open exclusively at this time, please try again later."
leavenow=.T.
RETURN
Today is tomorrow's yesterday.