Charles, I think is better to grab the PK in the same command as the insert with the OUTPUT clause of the insert. Something like
text to lcSQL textmerge noshow flags 1 pretext 1 + 2 + 4
INSERT INTO yourTable
(
yourFieldList
)
OUTPUT Inserted.yourPrimaryKey
VALUES
(
yourValuesList
)
endtext
llSuccess = Sqlexec(lnConnection, lcSQL, 'c_pk') = 1
lnNewPK = Iif(not llSuccess or Eof('c_pk') or c_pk.pk = 0, null, c_pk.pk) && Assuming PK is your primary key field name
"The five senses obstruct or deform the apprehension of reality."
Jorge L. Borges?
"Premature optimization is the root of all evil in programming."
Donald Knuth, repeating C. A. R. Hoare
"To die for a religion is easier than to live it absolutely"
Jorge L. Borges