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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replacing same field in mult. tables 1

Status
Not open for further replies.

MDoom

Programmer
Aug 31, 2001
52
US
I'm trying to create a little program to replace the value in the same field name in multiple tables at once using the following code but it isn't working.
Any suggestions? Thanks..

USE ....\wgesarea.dbf IN 1
USE ....\wgesdist.dbf IN 2
USE ....\wgessubd.dbf IN 3
USE ....\wgesbura.dbf IN 4

FOR j=1 TO 4
SELECT j
SCAN
SCATTER MEMVAR
IF m.distcd='43'
REPLACE distcd WITH '11'
ENDIF
ENDSCAN
ENDFOR

 
What's not working? I'd simplfy it with:
Code:
USE ....\wgesarea.dbf IN 1 
USE ....\wgesdist.dbf IN 2 
USE ....\wgessubd.dbf IN 3 
USE ....\wgesbura.dbf IN 4 

FOR jj = 1 TO 4
   SELECT jj
   REPLACE ALL distcd WITH '11' FOR distcd='43'
   USE && close this one
ENDFOR
Rick

 
An open table window comes up. The SELECT j or jj statement is not working because an error comes up stating 'no table is in use' even though all the tables open and are being used in the proper work area.
 
I would just use:

USE ....\wgesarea.dbf
=MyReplace()
USE ....\wgesdist.dbf
=MyReplace()
USE ....\wgessubd.dbf
=MyReplace()
USE ....\wgesbura.dbf
=MyReplace()
USE

FUNCTION MyReplace
REPLACE ALL distcd WITH '11' FOR distcd='43'
RETURN
Dave S.
 
OOPs,
That's what I get when I forget to test my code. Just left off a couple of parens ()'s:
Code:
USE ....\wgesarea.dbf IN 1 
USE ....\wgesdist.dbf IN 2 
USE ....\wgessubd.dbf IN 3 
USE ....\wgesbura.dbf IN 4 

FOR jj = 1 TO 4
   SELECT (jj)
   REPLACE ALL distcd WITH '11' FOR distcd='43'
   USE && close this one
ENDFOR
Rick

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top