Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Changing field values when table is not open.

Status
Not open for further replies.

woodyinoz

IS-IT--Management
Jan 8, 2002
215
GB
Hi all,

I am looking for some code that will enable me to change the values of certain fields in a table which is not open. The changes will be dependant upon certain "if" criteria.

If USER2 = "BR" AND MARK = "P.." then

USER2 = "BP"

endif


I know that tCursors can be used for this kind of thing but my experience with these are very limited.
I'm sure this is an easy process and would appreciate someone pointing me in the right direction.

Thanks,

Woody.
 
Well you could easily use a changeto query, but if you want to use a tCursor here's some code:

Code:
var
tcMytbl  tCursor
Markval  string
endvar
;
if not tcMytbl.open(":myAlias:myTable.db")
   then  errorShow()
         return
endif
;
if not tcMytbl.edit()
   then  errorShow()
         return
endif
;
scan tcMytbl:
;
MarkVal = tcMytbl."MARK"
if tcMytbl."USER2" = "BR" and Markval.substr(1,1) = "P"
  then tcMytbl."USER2" = "BP"
endif
;
endscan

tcMytbl.endEdit()
tcMytbl.close()




Mac :)

"Gurth a choth-en-America! Tôl acharn..."


langley_mckelvy@cd4.co.harris.tx.us
 
A table has to be opened somehow to make changes to its contents. On the surface, your requirement looks like the sort of stuff that could be done using a query.
First backup your table (make a copy using the utility menu). Create a new query on the table. Under the USER2 field input the condition
BR, changeto "BP"
Under the MARK field, input the condition
P..
Run the query.
 
Both of you seem to have very valid ideas upon how I can do this, however when trying both methods I have encountered problems.

With the TCursor code nothing at all happens with no changes being recorded.

With the query method I get the following error:

INSERT,DELETE,CHANGETO and SET rows may not be checked.

The row is checked so I'm not sure why this error is occuring.
 
Forget that, I've cracked it!!

Thanks very much for your help I was being a bit dim!!

Woody.
 
I never paused to think about that error message before, but now, on mature reflection, it is mis-leading and incorrect - clearly the rows may or may not be checked. However, they shouldn't be!. :eek:)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top