******************************************************************** * Description.......: OpenTble && Opens the passed table * Calling Samples...: OpenTble('TranMstr','WorkFile') * Parameter List....: tcTable, tcAlias, tcMode, tcTagOrder, tnBufferMode * Created by........: * Modified by.......: Nadya Nosonovsky 05/01/2001 11:34:13 AM ******************************************************************** function OpenTble && Opens, but doesn't select a table lparameters tcTable, tcAlias, tcMode, tcTagOrder, tnBufferMode * 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 * tcTagOrder - optional: Tag name * tnBufferMode - optional: Set buffer mode local lcTableName, lnPos, llDBCPrefix, lcDBCName, lcPath * Check parameters first if vartype(m.tcTable)<>'C' or empty(m.tcTable) * First parameter is required return .f. endif lnPos=rat('!',m.tcTable) if m.lnPos>0 && DataBase Name was specified && example: Support!PostOff lcTableName=juststem(substr(m.tcTable,m.lnPos+1)) && PostOff lcDBCName=upper(left(m.tcTable,m.lnPos-1)) && DBC Name llDBCPrefix=.t. else lcTableName=m.tcTable endif lcPath = justpath(m.tcTable) if vartype(m.tcAlias)<>'C' or empty(m.tcAlias) tcAlias=juststem(m.lcTableName) endif if vartype(m.tcMode)<>'C' or empty(m.tcMode) tcMode='shared' endif local lcCheckFile if empty(justext(m.lcTableName)) lcCheckFile=forceext(m.lcTableName,"dbf") else lcCheckFile=m.lcTableName endif if !file(m.lcCheckFile) && File doesn't exist =messagebox(m.tcTable +' does not exist!. Can not proceed...',48,'Error') return .f. endif local lnOldSelect lnOldSelect=select() if !used(m.tcAlias) or ; && Alias is not already in use or (m.llDBCPrefix and not juststem(cursorgetprop("DATABASE",m.tcAlias))==m.lcDBCName) or ; && it's not the same database (!empty(m.lcPath) and m.lcPath<>justpath(dbf(m.tcAlias))) local lcOldError, lnErr, lcOldSetExclusive use in select(m.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 (m.tcTable) again &tcMode in 0 alias (m.tcAlias) on error &lcOldError && Restore previous Error Handler if m.lcOldSetExclusive='ON' set exclusive on && Restore it back to original settings endif do case case m.lnErr=0 && Everything is OK case m.lnErr=1705 && File Access is denied =messagebox(m.tcTable +' is opened exclusively by another user. Can not proceed...',48,'Error '+transform(m.lnErr)) return .f. && Table could not be opened (already used exclusively) otherwise && Another error =messagebox(m.tcTable+' could not be opened!',48,'Error '+transform(m.lnErr)) return .f. endcase endif select (m.tcAlias) && If it's here, everything is all right if not empty(m.tcTagOrder) and vartype(m.tcTagOrder)='C' and tagno(m.tcTagOrder)>0 set order to tag (m.tcTagOrder) in (m.tcAlias) endif if vartype(m.tnBufferMode)='N' and between(m.tnBufferMode,1,5) set multilocks on =cursorsetprop('Buffering',m.tnBufferMode) && Note, we can not set buffering mode less than 3 on a view - no check for this endif select (m.lnOldSelect) && Return back to the original area return .t.>Hi.