title: cannot perform this operation on a open/closed dataset?
body: <p>Hi guys i've written a function which has to check the ID given to the function as <code>iID</code> and then output the name of the member of it is found, otherwise it must output that it is not found</p>
  
  <p>A different table is active when this function is called so it must change the table to <code>Members</code> (to search the ID) and then back again afterwards (I have multiple tables)</p>
  
  <pre><code>function fCheckID(iID:integer):String;
  var sTable:string;
  begin
  sTable:=datamoduleX.tableX.TableName;
  datamoduleX.tableX.TableName:='Members';
   if datamoduleX.tableX.Locate('RefNo',iID,[]) then
    result:=dmRooiX.tblRooiX['Name']+' '+datamoduleX.tableX['Surname']
    else
    result:='ID: '+inttostr(iID)+' does not exist';
  datamoduleX.tableX.TableName:=sTable;
  end;
  </code></pre>
  
  <p>but the problem is every time I call this function I get an error that says "Cannot perform this operation on an open dataset"</p>
  
  <p>if I close the dataset before I run the function I get "Cannot perform this operation on a closed dataset"</p>
  
  <p>I know the error occurs when I try to access the table name or change it (the function does not give the error when those 3 lines are commented out)</p>
  
  <p>I have no idea how to make this work
  any help would be greatly appreciated</p>