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

Change field property

Status
Not open for further replies.

peljo

Technical User
Mar 3, 2006
91
BG
Can you help me with the code to change the property of a field in a table.My field is called code and i want to change the property from text into number.I have made the following code:

Public Function ChangeProperty()

Dim tdf As DAO.TableDef
Dim fld As DAO.Field
Dim prp As DAO.Property
Dim dbs As DAO.Database
Set dbs = CurrentDb
Set tdf = dbs.TableDefs("Pricelist")
Set fld = tdf.Fields("code")
Set prp = fld.CreateProperty("Format", dbsingle)
fld.Properties.Append prp
dbs.Close
Set fld = Nothing
Set tdf = Nothing
Set dbs = Nothing

End Function

I get the following error :


Property value must be set before using this method.


 
I think you need to use Alter Table for this kind of action. Field type is read only once it has been appended. The trouble with Alter Table is it comes with all sorts of 'ifs'.
[tt]strSQL = "Alter Table pricelist Alter Column code Int"
CurrentDb.Execute strSQL[/tt]
 
He's trying to change the Format (I think) ... not the data type. It needs something like
Code:
Public Sub ChangeProperty()

    Dim tdf                         As DAO.TableDef
    Dim fld                         As DAO.Field
    Dim prp                         As DAO.Property
    Dim dbs                         As DAO.Database
    Set dbs = CurrentDb
    Set tdf = dbs.TableDefs("Pricelist")
    Set fld = tdf.Fields("code")

    Set prp = fld.CreateProperty("Format", dbText, "$#,##0.00;($#,##0.00)")
    fld.Properties.Append prp
    dbs.Close
    Set fld = Nothing
    Set tdf = Nothing
    Set dbs = Nothing
End Sub
The arguments for "CreateProperty" are

CreateProperty(name, type, value, DDL)

[small]On two occasions I have been asked, "Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?" I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question. (Charles Babbage)[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top