>>Check Re: Auto Refresh Key fields after insert with CA Thread #
1100805 Message #
1101047>
>The Message #
956056 link in the above message is most complete & comprehensive. I have understood that the following needs to be done:-
>
>?"1) Refresh IDENTITY field using [SELECT @@IDENTITY] command"
>oCA.InsertCmdRefreshFieldList="f_IDENTITY"
>oCA.InsertCmdRefreshCmd="SELECT @@IDENTITY"
>
>
>Will that update my VFP cursor?
>
>I need some help with my class. I tried the following on CA class built using Mark E. McCasland's builder :-
>
>lAutoRefreshNewRecords= .T.
>lUseDefaultRefreshCmd= .F.
>
>cInsertCmdRefreshFieldList= acbalid
>
> _BuildDefaultRefreshCmd method as
>
>TEXT TO THIS.InsertCmdRefreshCmd TEXTMERGE NOSHOW PRETEXT 10
> SELECT @@IDENTITY
>ENDTEXT
>
>
>The above in theory should work but I must have done something wrong. Any help from anyone is welcome.
>
>>There is also a nice article at
http://www.foxclub.ru/articles/index.php?id=46#CursorAdapter, but unfortunately, in Russian.
>
>I wish my russian was better. :)
What exactly is not working? Was the new record correctly inserted?
As alternative, you may use AfterInsert method with the code from the article above:
PROCEDURE AfterInsert
LPARAMETERS cFldState, lForce, cInsertCmd, lResult
IF lResult=.T.
LOCAL currentArea
currentArea=SELECT()
TRY
IF 1=SQLEXEC(this.DataSource,"SELECT NewIdent=@@IDENTITY","NewIdent")
REPLACE TabId WITH NewIdent.NewIdent IN (This.Alias)
USE IN IDRes
ELSE
LOCAL laError(1)
=AERROR(laError)
ENDIF
FINALLY
SELECT (currentArea)
ENDTRY
ENDIF
ENDPROC
This would work for VFP8 too.
If it's not broken, fix it until it is.
My Blog