>******************************************************************** >* Description.......: OpenTable && Opens the passed table >* Calling Samples...: OpenTable('TranMstr','WorkFile') >* Parameter List....: tcTable, tcAlias, tcMode, tcOrder, tnBufferMode >* Created by........: >* Modified by.......: Nadya Nosonovsky 01/10/2001 11:46:19 AM >******************************************************************** >function OpenTable >lparameters tcTable, tcAlias, tcMode, tcOrder, tnBufferMode >=messagebox( "tcTable "+tcTable+ chr(13)+"tcOrder "+iif(!empty(tcOrder),tcOrder,"")) >* tcTable - required: name of table to open (with or without full path) >* tcAlias - optional: alias name, if different from tcTable >* tcMode - optional: mode in which table should be opened, like Shared noupdate >* tcOrder - optional: Tag name >* tnBufferMode - optional: Set buffer mode >local lcTableName, lnPos, llDBCPrefix, lcDBCName >* Check parameters first >if empty(tcTable) or vartype(tcTable)'C' >* First parameter is required > return .f. >else > lnPos=rat('!',tcTable) > if lnPos>0 && DataBase Name was specified && example: Support!PostOff > lcTableName=juststem(substr(tcTable,lnPos+1)) && PostOff > lcDBCName=upper(left(tcTable,lnPos-1)) && DBC Name > llDBCPrefix=.t. > else > lcTableName=tcTable > endif >endif >if empty(tcAlias) or vartype(tcAlias)'C' > tcAlias=juststem(lcTableName) >endif > >if empty(tcMode) or vartype(tcMode)'C' > tcMode='shared' >else > tcMode=lower(tcMode) >endif >local lcCheckFile >if empty(justext(lcTableName)) > lcCheckFile=forceext(lcTableName,"dbf") >else > lcCheckFile=lcTableName >endif >if !file(lcCheckFile) && File doesn't exist > =messagebox(tcTable +' does not exist!. Can not proceed...',48,'Error') > return .f. >endif >local lnOldSelect >lnOldSelect=select() >if !used(tcAlias) or ; && Alias is not already in use or > (llDBCPrefix and not juststem(cursorgetprop("DATABASE",tcAlias))==lcDBCName) && it's not the same database > local lcOldError, lnErr, lcOldSetExclusive > use in select(tcAlias) && Close table > lnErr=0 > lcOldError=on('error') && Save current Error Handler > lcOldSetExclusive=set('exclusive') && Save current exclusive status > set exclusive off && This should be always set this way > on error lnErr=error() > use (tcTable) again &tcMode in 0 alias (tcAlias) > on error &lcOldError && Restore previous Error Handler > if lcOldSetExclusive='ON' > set exclusive on && Restore it back to original settings > endif > if lnErr0 && Error occurs > if lnErr=1705 && File Access is denied > =messagebox(tcTable +' is opened exclusively by another user. Can not proceed...',48,'Error '+transform(lnErr)) > return .f. && Table could not be opened (already used exclusively) > else && Another error > =messagebox(tcTable+' could not be opened!',48,'Error '+transform(lnErr)) > return .f. > endif > endif >endif > >select (tcAlias) && If it's here, everything is all right >if !empty(tcOrder) >if not empty(tcOrder) and vartype(tcOrder)='C' and tagno(tcOrder)>0 > set order to tag (tcOrder) >endif >suspend >endif > >if vartype(tnBufferMode)='N' and between(tnBufferMode,1,5) > local lcOldSetMultilocks > lcOldSetMultilocks=set('multilocks') > set multilocks on > =cursorsetprop('Buffering',tnBufferMode) && Note, we can not set buffering mode less than 3 on a view - no check for this > if lcOldSetMultilocks="OFF" > set multilocks off && Restore back > endif >endif >select (lnOldSelect) && Return back to the original area > >return .t.Maybe you could use the "SET ORDER TO TAG whatever IN wherever" format of the command. That way, it won't matter what the current area is when you get there. You might also have to change the TAG() function to use the optional area/alias, too. And other commands that might be dependant on the current area.