ThisForm.mExecuteSqlCommand(lcSql, 'curSecondDefects', '').. during the execution of mExecuteSqlCommand the form's datasession is current.
loSession = create('session') Thisform.mExecSQL_DS( "select ..from..", loSession.DataSessionID ... * in the form class: function mExecSQL_DS( cSQLCommand, nDataSessionID ) local nSaveDataSessionID nSaveDataSessionID = set("datasession") set datasession to (m.nDataSessionID) sqlexec( ..., m.cSQLCommand, ... ) set datasession to (m.nSaveDataSessionID) return endfuncSaving and restoring the current datasession is important because the current datasession on exit from a method will change the object's datasession. You possibly should consider a TRY .. FINALLY block or some equivalent around the code where the datasession is switched. Getting into the pros and cons of this is beyond the scope of this message!
* In globals.prg or whatever function ExecSQL( oForm, cSQL ) sqlexec( oForm.ConnectionHandle, m.cSQL ) endfuncAgain, plus all the stuff a generic function should have, return values, parameters, error handling