Rob: It's hard to test without your environment, but this should get you going. I've adapted the original example I gave you into a Function which I am calling inside your for loop. Let me know if you need clarification on how this works.
I also added a type to your declaration of Vqamainbal.
#include "sbasic_include.sbas"
FUNCTION PostToAccount(vMatch as String, vAmount as Money) as Int
var vRet as Int
var vRS as Int
vRet = 0
// Open a result set with the correct Account record
vRS = @XResultSetSearch("data\ron\qamain.db", "QAMain", SEARCH_MODE_AND,SEARCH_SYNTAX_QA, "!AccountID=" + vMatch)
If vRS > -1
{
// Make sure there is exactly one matching record
If @XResultSetTotal(vRS) = 1
{
// Make sure we can change the record
If @XResultSetLocked(vRS) = 0
{
// Update the account record
XResultSetValue(vRS, "QAmain bal after adjustment", @Str(vAmount))
}
Else
{
vRet = 3
}
}
Else
{
vRet = 2
}
XResultSetClose(vRS) // Close the result set
}
Else
{
vRet = 1
}
Return vRet
END FUNCTION
var vRSHandle as int
var vNoOfRecords as int
var vLoop as int
var vAccountNo as string
var vClient as string
var VName as string
var VServiceFee as string
var Vqamainbal as Money
var vFlag as Int
vRSHandle = @XResultSetSearch("data\ron\costs.db", "Costa", SEARCH_MODE_OR, SEARCH_SYNTAX_QA, "")
if(vRSHandle > -1)
{
vNoOfRecords = @XResultSetTotal(vRSHandle)
for vLoop = 1 to vNoOfRecords
XResultSetCurrentPosition(vRSHandle, vLoop)
vAccountNo = @XResultSetValue(vRSHandle, "Acct no")
vClient = @XResultSetValue(vRSHandle, "Client")
vName = @XResultSetValue(vRSHandle, "Name")
vServiceFee = @XResultSetValue(vRSHandle, "Service Fee")
vqamainbal = @XResultSetValue(vRSHandle, "QAmain bal after adjustment")
WriteLn(@Str(vLoop) + " Of " + @Str(vNoOfRecords) + " Account: " + vAccountNo + " cleint: " + vclient +" Name: " + vname + " Service Fee " + vServiceFee)
vFlag = PostToAccount(vAccountNo, vqamainbal)
If vFlag <> 0
{
WriteLn("Error posting to account: " + vAccountNo, "Error Code: " + @Str(vFlag), "")
}
next
XResultSetClose(vRSHandle)
}