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

Altering / Modifying Client Tables

Databases and tables

Altering / Modifying Client Tables

by  jimoo  Posted    (Edited  )
See if the field ôcalcmethodö exist, add it if necessary.

PSUEDO Code
* This is what the program does.
If [the field does not not exist on the table]
If [able to add the field to the table]
* Add the new field and continue
ELSE
* The field does not exist and unable to add it
* Provide Error Message
ENDIF
ELSE
* Field exists already on table - no action required
* Go On
ENDIF

VISUAL FOXPRO CODE

* I like to add a date check to limit how long the code is executed.
* This is just in case I forget to take it out.
* It prevents unnessary opening / closing of tables over time.
IF DATE() < {08/01/2003}
* The date-check provides plenty of time for the change to occur and stops
* unnecessary opening / closing of tables if another version is not released
* with this code commented out, or I forget to comment out the temporary code.

SELECT 0
USE joblist
AFIELDS(laFields)
IF ASCAN(laFields,"CALCMETHOD") > 0
* the field already exists
* close the table, and go on our merry way
USE
ELSE
* reopen it - this time exclusively so we can modify the structure
USE joblist EXCL

* The USE command closes the table (if necessary) and then tries to reopen it.
* Therefore, the table will not be open if the Exclusive-Use failed, even if
* it were open prior to it.

IF USED('joblist')
* opened exclusively okay
ALTER TABLE joblist ADD COLUMN calcMethod C(4) NOT NULL

* now close it
USE

MESSAGEBOX("Update Successful! - The new CalcMethod field has been " +;
"added...","MyClientName")

ELSE
* Houston, we have a problem.
MESSAGEBOX("Update Failed! - Unable to add the new CalcMethod field " +;
"because the joblist table cannot be opened exclusively at this time. "+;
"Have everyone exit the System and try it again.","MyClientName")

RETURN

ENDIF

ENDIF
ENDIF

Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top