There may be a handy ADO facility, but I'm not aware of one.
I use the funtion below, which you're welcome to.
Have fun
Simon
type
TCopyRecordOption=(crReturnToOriginal,crReturnNewAutoincValue);
TCopyRecordOptions=set of TCopyRecordOption;
TAction=(crCopy,crIgnore,crSet,crAutoinc);
function CopyRecord(ADataset:TDataset; AIgnoreFields,ASetFields:array of string;
ASetValues:array of variant; AOptions:TCopyRecordOptions=[]):integer;
var
i,q:integer;
LAction:array of TAction;
LValues:array of variant;
LBookmark:TBookmark;
LAutoincFieldIndex:integer;
begin
Result:=0;
LAutoincFieldIndex:=-1;
with ADataset do begin
{Provide room in arrays}
SetLength(LAction,Fields.Count);
SetLength(LValues,Fields.Count);
if(crReturnToOriginal in AOptions)then
LBookmark:=GetBookmark
else
LBookmark:=nil;
try
{Note existing values and what to do with each field}
for i:=0 to Fields.Count-1 do
with Fields do
if(ClassType=TAutoIncField)then begin
if(crReturnNewAutoincValue in AOptions)and
(LAutoincFieldIndex=-1)then begin
LAutoincFieldIndex:=i;
LAction:=crAutoInc;
end else
LAction:=crIgnore;
end else
if(ReadOnly)or
(InTextList(FieldName,AIgnoreFields)<>-1)or
(ClassType=TDatasetField)then
LAction:=crIgnore
else begin
q:=InTextList(FieldName,ASetFields);
if(q<>-1)then begin
LAction:=crSet;
LValues:=ASetValues[q]; {Alternative is to find q later on}
end else begin
LAction:=crCopy;
LValues:=Value;
end;
end;
{Create new record}
Append;
{Put in values}
for i:=0 to Fields.Count-1 do
case LActionof
crCopy,crSet:Fields.Value:=LValues;
end;{case}
{Post; No post. Can hide record if filtered or a detail recordset}
{Note new autoindex field value if required}
if(crReturnNewAutoincValue in AOptions)and
(LAutoincFieldIndex>=0)then
Result:=Fields[LAutoincFieldIndex].asInteger;
finally
if(crReturnToOriginal in AOptions)then begin
GotoBookmark(LBookmark);
FreeBookmark(LBookmark);
end;
end;
end;
end;