SQL timing

I have a button that allows data to be reordered via a sort order field in a table. It works great, most of the time. Occasionally if clicking the move up or move down button rapidly it is possible to end up with two rows with the same sort order. This situation requires manual recovery. Is there any way to prevent this occurrence? I have tried adding a running flag, but that does not seem to have any effect.

From the actionPerformed on the order button:

[code]OrderNumber = event.source.parent.getComponent(‘Sequence Table’).OrderNumber
data = event.source.parent.getComponent(‘Sequence Table’).data
row = event.source.parent.getComponent(‘Sequence Table’).selectedRow
Running = event.source.Running

if row > 0 and Running != 1:
event.source.Running = 1
currentSort = data.getValueAt(row,“SortOrder”)
#get previous record
sql = “SELECT TOP 1 ORDER_NUMBER FROM tblSequence WHERE SortOrder < %d ORDER BY SortOrder DESC”
omsPrev = system.db.runScalarQuery(sql %(currentSort))
sql = “UPDATE tblSequence SET SortOrder = SortOrder + 1 WHERE ORDER_NUMBER = ?”
system.db.runPrepUpdate(sql, [omsPrev])
sql = “UPDATE tblSequence SET SortOrder = SortOrder - 1 WHERE ORDER_NUMBER = ?”
system.db.runPrepUpdate(sql, [OrderNumber])

event.source.parent.getComponent('Sequence Table').selectedRow = row -1
system.db.refresh(event.source.parent,"Sequence")
event.source.Running = 0

[/code]

why not use the running bit to disable the button until the change has been completed to prevent multiple clicks and a timing issue?

That sounds easier than my idea: Combine the three queries into one query.

Not sure, but an invokeLater might be used to process the event, then run the script.