I have been updating a BE with a conversion Db to add/alter fields and the code I was working with stopped working with no change to my OS or Access ver. Windows XP, Access 2010.
This worked previously:
PubstrFilePath is the path to the BE Db.
Set db = OpenDatabase(PubstrFilePath)
db.Execute "ALTER TABLE tblPartStation ADD COLUMN PlantUsage Double"
With db.TableDefs("tblPartStation")
.Fields("PlantUsage").Properties("DefaultValue") = 0
End With
db.TableDefs.Refresh
Set tdf = db.TableDefs("tblPartStation")
Set fld = tdf.Fields("PlantUsage")
Set prop1 = fld.CreateProperty("DecimalPlaces", dbByte, 2)
With fld
.Properties.Append prop1
.DefaultValue = 0
End With
db.TableDefs.Refresh
I had to change it to this to get it to work this week:
Set db = OpenDatabase(PubstrFilePath)
db.Execute "ALTER TABLE tblPartStation ADD COLUMN PlantUsage Double"
Set db = OpenDatabase(PubstrFilePath)
With db.TableDefs("tblPartStation")
.Fields("PlantUsage").Properties("DefaultValue") = 0
End With
Set tdf = db.TableDefs("tblPartStation")
Set fld = tdf.Fields("PlantUsage")
Set prop1 = fld.CreateProperty("DecimalPlaces", dbByte, 2)
With fld
.Properties.Append prop1
.DefaultValue = 0
End With
While I still don't understand why one method quit working after months of use my main concern is am I missing something easier or more direct.
Is there a more succinct way of accomplshing the add/alter of a field?
Thanks for looking.
Joel
Joel
This worked previously:
PubstrFilePath is the path to the BE Db.
Set db = OpenDatabase(PubstrFilePath)
db.Execute "ALTER TABLE tblPartStation ADD COLUMN PlantUsage Double"
With db.TableDefs("tblPartStation")
.Fields("PlantUsage").Properties("DefaultValue") = 0
End With
db.TableDefs.Refresh
Set tdf = db.TableDefs("tblPartStation")
Set fld = tdf.Fields("PlantUsage")
Set prop1 = fld.CreateProperty("DecimalPlaces", dbByte, 2)
With fld
.Properties.Append prop1
.DefaultValue = 0
End With
db.TableDefs.Refresh
I had to change it to this to get it to work this week:
Set db = OpenDatabase(PubstrFilePath)
db.Execute "ALTER TABLE tblPartStation ADD COLUMN PlantUsage Double"
Set db = OpenDatabase(PubstrFilePath)
With db.TableDefs("tblPartStation")
.Fields("PlantUsage").Properties("DefaultValue") = 0
End With
Set tdf = db.TableDefs("tblPartStation")
Set fld = tdf.Fields("PlantUsage")
Set prop1 = fld.CreateProperty("DecimalPlaces", dbByte, 2)
With fld
.Properties.Append prop1
.DefaultValue = 0
End With
While I still don't understand why one method quit working after months of use my main concern is am I missing something easier or more direct.
Is there a more succinct way of accomplshing the add/alter of a field?
Thanks for looking.
Joel
Joel