lcCommand=; > "INDEX ON " + AllTrim(IndxExpr) + ; > " TAG " + Alltrim(TagName) + ; > IIF(Not Empty(Filter), " FOR "+Alltrim(Filter), " ") + ; > + ; > IIF(UPPER(Type)="CANDIDATE"," CANDIDATE","") + ; > IIF(TAGCOUNT(lcTableName) > 0, " ADDITIVE", "")Thanks a lot. I changed it to this and now it works just fine. I have some problems with content of my IndxDict, but it's another issue.
*!* Generate State.DBC from "scratch" *!* Check the existence of State.DBC Local lcStatePath, lcStateDBC, lcStateFiles, lcSafety, lnResponse *!* Hardcoded path - check this lcStatePath="M:\REDP\DBC\StateTest\" lcStateDBC=lcStatePath+"StateTest.DBC" lcStateFiles=lcStatePath+"*.*" lcSafety=SET('Safety') IF lcSafety="ON" SET SAFETY OFF ENDIF IF File(lcStateDBC) && check existence of this file IF DBUSED(lcStateDBC) && Database is open, can not proceed =MessageBox ("File "+lcStateDBC +" is open now. Can not proceed!", 48, "Warning") return .f. ELSE lnResponse=; MessageBox ("All files in "+lcStatePath +" will be deleted now! Are you sure?", 4+48, "Warning") if lnResponse=6 && Yes ERASE (lcStateFiles) && Delete files else return .f. endif ENDIF ENDIF wait window nowait "Wait while State.DBC generating..." SELECT DataDict Local laTableNames Local lnTagCount, lni, lnk, lcOrder, lcTableName,; lcTempPath, lcTempTable, lcTempSelect, lcTempFiles, ; lcFieldName, lcComment, lcCaption,lcNextIDTable lnTagCount=TAGCOUNT() lcTempPath="c:\windows\temp\" && Temp path hardcoded lcTempTable=lcTempPath+"tempror.dbf" && Temp table hardcoded lcTempFiles=lcTempPath+"tempror.*" && Temp files hardcoded lcOrder=Order() && Save the current order DIMENSION laTableNames[lnTagCount-2] *!* Hardcoded TableNames lnk=1 FOR lni=1 to lnTagCount if UPPER(TAG(lni))="FIELD_NAME" OR ; UPPER(TAG(lni))="BLDMSTR" ** Skip it else laTableNames[lnk]=TAG(lni) lnk=lnk+1 endif ENDFOR CREATE DATABASE (lcStateDBC) && Create State.DBC, database open automatically lnk=0 FOR lni=1 TO ALEN(laTableNames,1) lcTableName=Proper(laTableNames[lni]) SELECT * FROM DataDict WHERE &lcTableName>0 ; INTO DBF (lcTempTable) && Select only set of records IF _TALLY>0 && To be sure lnk=lnk+1 lcTempSelect=Alias() INDEX ON (lcTableName) TAG (lcTableName) GO TOP Replace Table_Name with LOWER((lcTableName)) create (lcStatePath+lcTableName) DATABASE (lcStateDBC); from (lcTempTable) && Creates table within DBC (AssrMstr, PropMstr, etc.) IF NOT USED(lcTempTable) USE (lcTempTable) Alias (lcTempSelect) in 0 ENDIF SELECT (lcTempSelect) && Select Temprorary table SCAN lcFieldName=Lower(lcTableName)+'.'+lower(alltrim(field_name)) lcComment=Left(Alltrim(Definition),255) lcCaption=Alltrim(Header) DBSETPROP(lcFieldName, 'field', 'comment', lcComment) DBSETPROP(lcFieldName, 'field', 'caption', lcCaption) ENDSCAN USE IN (lcTempSelect) ERASE (lcTempFiles) *!* Create indexes SELECT (lcTableName) && Assume that this table is open exclusive DELETE TAG ALL SELECT IndxDict SCAN FOR UPPER(Table)=Upper(lcTableName) lcCommand=; "INDEX ON " + AllTrim(IndxExpr) + ; " TAG " + Alltrim(TagName) + ; IIF(Not Empty(Filter), " FOR "+Alltrim(Filter), "") + ; IIF(UPPER(Type)="CANDIDATE"," CANDIDATE","") + ; IIF(TAGCOUNT(lcTableName) > 0, " ADDITIVE", "") SELECT (lcTableName) &lcCommand SELECT IndxDict ENDSCAN ENDIF ENDFOR ** Add NextID table lcNextIDTable=lcStatePath+"NextID" CREATE TABLE (lcNextIDTable)(Table C(8), ID I) Alter Table (lcNextIDTable) Alter Column Table; SET CHECK !Empty(Table) ERROR "Table should have a value" Alter Table (lcNextIDTable) Alter Column ID; SET CHECK !Empty(ID) ERROR "ID should have a value" Index on UPPER(table) TAG TABLE CANDIDATE CLOSE DATABASE && Close State.DBC WAIT CLEAR =MessageBox(Alltrim(str(lnk+1))+" tables were created",0,"Information") SET SAFETY &lcSafety SELECT DataDict IF NOT Empty(lcOrder) SET ORDER TO (lcOrder) ENDIF *******************************************I also would issue a USE and FLUSH afterwards to make certain that the updated .CDX file is forced out to disk completely.