OK, folks, after a little experimentation,
I found that the problem doesn't appear to be with
FETCH LAST, but with FETCH REC n.

More specifically, if the Info Tool window is open,
showing a record from the table in question, then

Run Command "FETCH REC"+str$(n)+" From "+t

doesn't appear to have any effect!  Instead, the 
table's "current row" is the one showing in the
Info window.

There are three workarounds, depending upon what you want
to do:

1. Close the Info window before any invocation of the code.
2. Set the Info window's current row to the row you're duplicating.
3. Avoid the issue and use the slower SELECT method.

Oh well, at least I hope you found this entertaining.

Best regards
Spencer
 
- - - - - - - - - - Code - - - - - - - - - -

function DuplicateRow (ByVal t as string,
                             col (0) as string,
                       ByVal cols as smallint,
                       ByVal r as integer) as integer

dim a as alias
dim icols as string
dim qcols as string

qcols = t + "." + col (1)
icols = col(1)
if cols > 1
   then for i = 2 to cols
            qcols = qcols + "," + t + "." + col (i)
            icols = icols + "." + col (i)
        next
end if
a = t + ".rowid"

run command "fetch rec "+str$(r)+" from "+str$(t)
'
' BAD NEWS if the Info window is open!
'
run command "insert into "+t+" ("+icols+") values ("+qcols+")" 

fetch last from t
DuplicateRow = a
end function


---------------------------------------------------------------------
List hosting provided by Directions Magazine | www.directionsmag.com |
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
Message number: 10309

Reply via email to