I'd prefer Mikes second approach.
But in both approaches you avoid an error that otherwise hints on doing something wrong. That's the wrong kind of silencing and stabilizing an application. If you want to move to nPos in some table and this code now does not do so, as it sees nPos > RECCOUNT(), the move isn't done and that doesn't error. So far, so fine, but you might afterwards operate on a different record than you think in the table, as there was no goto. Working on the current record instead or RECNO() = nPos can have all kind of bad consequences, just because you prevented the error.
Your real error must be somewhere further up the drain, previously. Either you set nPos wrong or you work in the wrong workarea, the wrong table. If you find out why nPos>reccount() or that you switched to a wrong workarea, then you may fix that and the code could stay. To be prepared for the general case of a wrong nPos you could also put this into a function SAFEGOTO(nPos), which returns .F. when it didn't go to nRec, but that also won't bring you to fixing the real bug further up the drain somewhere.
It has some advantage to work with code in any active workarea, it's generic and all you need is SELECT sometable beforehand. In that mindset you still have to be cautious its the correct workarea, but you then obviously don't want to use IN clauses but profit from the default behaviour of many commands to work in one current workarea. Then you could still make it more safe by put the GOTO in TRY CATCH and check if RENO()=nPos after the GOTO:
Code:
TRY
GOTO nPos
CATCH
*
ENDTRY
IF RECNO()=nPos
* Do something at nPos
ELSE
* Record not found.
ENDIF
Ideally you find out why your nPos or your current workarea were wrong. Especially if it's code from someone else, you don't easily changre all of it to work with a new paradigm to eg always specify IN tablename. I do the latter, as very few code can be used on all tables, your code normally is specific to a certain table and thus can be as verbose as it can be to work on that table and not accidentally work on some other table just by a flaw in selecting the wrong workarea.
Bye, Olaf.