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!

Need code to change field name, type and size in a table structure 1

Status
Not open for further replies.

elevator

Programmer
Apr 23, 2002
19
US
I need to change a field name, the type and size
from Form pushButton code. I would also like to know if it can be done from a query.

 
Yes.
But you cannot restructure a table if it has a lock on it by you or someone else.

You can change the field name of the result table with a query, but not its type or size. Not in the context of the Restructure command. See Restructure in the Help | ObjectPAL Reference

If you need to change a field’s properties, I would recommend that you create another table and populate it with the appropriate data.
 
I have field in a table that with a numeric format. I cannot change structure of this tables because it is part of an application.

I do have an answer table that I can restructure to change the structure. I have done it manually, but I need the code to change it via a form.

I need to change a numeric type to an alpha type with a size of 20.
 
A slightly modified codes from Help | ObjectPAL Reference | Restructure's Example

var
tbl Table
tcFlds TCursor
dynNewStru DynArray[] Anytype
endvar

tbl.attach( ":pRIV:Answer.db" )
tbl.enumFieldStruct( ":pRIV:field_struct.db")

tcFlds.open(":pRIV:field_struct.db" )
tcFlds.edit()

scan tcFlds :
if tcFlds."Field Name" = "FIELD001" then
tcFlds."Type" = "ALPHA"
tcFlds."Size" = "20"
quitLoop
endif

endscan
tcFlds.endEdit()
tcFlds.close()

dynNewStru["FIELDSTRUCT"] = ":pRIV:field_struct.db"
tbl.restructure( dynNewStru )

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top