Field Caption in Table

B

Benard

After a new field in a table is created in access vbasic
the Caption property is null. Is there any way of writing
the Caption property? A Caption property can be changed if
it has previously been set but in a new field it has not
been set and I can find no way of setting it.
 
B

Bernard

-----Original Message-----
Post up your code and I'll take a crack at it.
--
Scott N. Weber, MCP
http://www.AccessYourBiz.Com
Customizable Accounting Software
Written with Microsoft Access




.
Set tdfAllPrices = db.TableDefs("tblAllPrices")
'Add the new field to tblAllPrices
Set fldShare = tdfAllPrices.CreateField
(strNewNameID, dbCurrency)
tdfAllPrices.Fields.Append fldShare
Set fld = tdfAllPrices.Fields("AZN")
fld.Properties("Caption") = "Hello"

The above code works and sets a new field strNewName.
Provided the Caption property for the field AZN(or any
field) has

been set in the table tblAllPrices, when the table is in
design mode and the database has been closed and restarted
the

Caption will be changed to Hello. if the Caption is null
it wont be changed as it cant find the property( see
Microsoft

Knowledge Base Article - 132019 )
If I change "AZN" to strNewNameID then again it can't find
the property.
Is there any way to set the Caption property of a newly
created field in access v basic?
 
D

Douglas J. Steele

When you try to access the Caption property, you should get an Error 3270.

Use CreateProperty to create the property in that case.

Set tdfAllPrices = db.TableDefs("tblAllPrices")
'Add the new field to tblAllPrices
Set fldShare = tdfAllPrices.CreateField(strNewNameID, dbCurrency)
Set prpCaption = fldShare.CreateProperty("Caption", dbText, "Caption
for new field")
fldShare.Properties.Append prpCaption
tdfAllPrices.Fields.Append fldShare
 
B

Bernard

-----Original Message-----
When you try to access the Caption property, you should get an Error 3270.

Use CreateProperty to create the property in that case.

Set tdfAllPrices = db.TableDefs("tblAllPrices")
'Add the new field to tblAllPrices
Set fldShare = tdfAllPrices.CreateField (strNewNameID, dbCurrency)
Set prpCaption = fldShare.CreateProperty("Caption", dbText, "Caption
for new field")
fldShare.Properties.Append prpCaption
tdfAllPrices.Fields.Append fldShare



--
Doug Steele, Microsoft Access MVP

(no e-mails, please!)






.
Many Thanks
Your code works. I had tried it before but I either got it
slightly wrong but I believe I continued to look at the
caption in the AZN field when I was setting it in the new
field!!!!!!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top