Hi
This is a small sample , replace the BG_BUG_ID and BUG by the field , Table you need in.
Sub Bug_MoveTo
set td = TDConnection
set com = td.command
com.CommandText = "select max( BG_BUG_ID) from BUG "
set rec = com.Execute
msgbox rec.FieldValue(0)
set com = nothing
set rec = nothing
set td = nothing
End Sub