visual-foxpro

Update cursor value in Visual Foxpro 6


I have a cursor in Visual Foxpro 6 created as follows.

select month, memid, mname, bt, st, bh, sh, totk, toth, sum(totk*0.025)/100 as laga, sum(toth*0) as hchg, sum(totk*0.050)/100 as Tax ;
from abc2 ;
group by memid ;
order by 2 ;
into curs abc3


IF !USED("abc3")
USE abc3 in 0
ENDIF

select abc3 
go top
do while not eof()
update abc3 set month =  Thisform.txtReportHeader.Value
skip
ENDDO

The line 'update abc3 set month = Thisform.txtReportHeader.Value' gives me an error, saying I cannot update the cursor. How can I update this column with the value of the text field 'Thisform.txtReportHeader.Value'?


Solution

  • To make a cursor updateable you need to use the READWRITE clause. ie:

    select * from myTable into cursor crsX READWRITE
    

    However, if I remember right, READWRITE was introduced in VFP7. If it is right, then you should use the old trick to make it updatable:

    So your code become:

    Select Month,memid,mname,bt,st,bh,sh,totk,toth,Sum(totk*0.025)/100 As laga,Sum(toth*0) As hchg,Sum(totk*0.050)/100 As Tax ;
        from abc2 ;
        group By memid ;
        order By 2 ;
        into Curs abc3_tmp ;
        nofilter
        
    USE DBF('abc3_tmp') IN 0 AGAIN ALIAS abc3   
    
    Update abc3 Set Month =  Thisform.txtReportHeader.Value
    
    * You don't need to select it to update it. 
    * And you also don't need a loop to do that
    * If you wanted to limit the updated rows you would use a WHERE clause
    
    *Select abc3 
    

    PS: Although this kind of SQL works and doesn't give an error in VFP7 and earlier, try writing valid SQL without any ambiguity. That is, include all your non-aggregate columns in the group by. If you can't, then think twice that there might be something wrong with your query.