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

Checking for a field in VFP 6.0

Status
Not open for further replies.

rene316

Programmer
Jan 14, 2002
81
US
I have a program I am working on. In the program, I use the alter table command to add fields, change lengths, and rename the field. My question is... Is there a way to check for a field that is already there so that when you run the program you don't get the "field already exists or duplicate field" and just skip that line so the user doesn't have to keep hitting ignore. Mabye to clarify a little better, You run the program and it goes and adds all the fields you need, then you have to re-run it for some reason but the structure of the database already has the fields you want to add because you ran the program already, I want to be able to just run the program without having to hit ignore, rather than removing those fields prior to running the program so I dont get that message. Any help would be greatly appreciated.

Thanks in advance,
Rene
 
Rene,
The best techique is to open the table and use AFIELDS() to check (ASCAN?) if the field exists and it is defined the way you expect it.

Rick
 
Concur with Rick, thos combinations work fine. I have code that exactly what you are doing. It checks to see if the field exists and then alters the table if it can get exclusive access to the table. The code is on my laptop and I am using my desktop right now.

If you still need assistance send me an email and I'll send you the code snippet later.

jimo@deltabg.com



Jim Osieczonek
Delta Business Group, LLC
 
Hi!,
For what it's worth here is part of my code I put in my startup=prg
-Bart

FUNCTION modify_table_Leden
IF !USED("leden")
USE leden excl in 0
ENDIF
SELECT leden
IF type("Leden.Silagezin")="U"
ALTER TABLE Leden add COLUMN silagezin c(8)
DBSETPROP('LEDEN.SilaGezin', 'Field', 'InputMask', "99999999")
DBSETPROP('LEDEN.SilaGezin', 'Field', 'Caption', "silaPEnr")
ENDIF
UPDATE LEDEN SET plaats=UPPER(plaats)

if type("Leden.GezRelatie")="U"
alter table Leden add column GezRelatie C(10)
ENDIF

if type("Leden.SILA_m_dat")="U"
alter table Leden add column Sila_m_dat D
ENDIF
if type("Leden.SILA_m_srt")="U"
alter table Leden add column SILA_m_srt C(2)
ENDIF

USE
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top