The place to play "asterisk" in the article is to focus attention, because the author here has walked a detour, wasting an afternoon wandering in the MSDN. Now let's share it with you.
This article explains how to read and write this property in VBA. Unfortunately, the Caption property of the Field object is not an ADO native object, but a "Access property accessible by ADO", which describes two ways to access this property in the Help document, one that utilizes ADO, a DAO, where I say the result directly, Since the Field object is not a AccessObject object in ACCESS2003 and previous versions, there is no accessobjectproperties attribute, so we don't want to solve this problem in ADO, Now give the DAO Code solution
Subsetproperty (dbstempasdao.field,strnameasstring,_ bootempasstring) dimprpnewasdao.property DimerrLoopAsError ' Attempttosetthespecifiedproperty.
Onerrorgotoerr_property dbstemp.properties (strName) =bootemp OnErrorGoTo0 exitsub err_property:
' Error3270meansthatthepropertywasnotfound. Ifdbengine.errors (0). Number=3270then
' Createproperty,setitsvalue,andappendittothe ' propertiescollection.
Setprpnew=dbstemp.createproperty (Strname,_ dbtext,bootemp)
DbsTemp.Properties.AppendprpNew Resumenext Else
' Ifdifferenterrorhasoccurred,displaymessage. Foreacherrloopindbengine.errors
MsgBox "errornumber:" &errloop.number&vbcr&_ errloop.description Nexterrloop End EndIf
Endsub subdisplayclumcaption (Byvaltbnameasstring,byvalfldindexasinteger)
DIMDSETASDAO.TABLEDEF)//***** must use TableDef object
Dimiasintegerdimtmppropasdao.property//Forced to use DAO type
Dimfldasdao.field//Forced to use DAO type dimtmptxtasstring ' Onerrorresumenext
Dimmsgasstringdimcdbasdao.database//***** forced to use DAO type
Setcdb=currentdb//**** key, determining static references to the current database
Setdset=cdb. TableDefs (tbname)//***** must use TableDef object
Foreachfldindset.fields tmptxt=fld. Name setpropertyfld, "Caption", Tmptxt msg=msg fld. Properties ("Caption")
Msg=msg Chr (a) Chr nextfld msgboxmsgendsub
Here the code has two sub, one is SetProperty, to determine whether a field has a specified property, if not set, there will be the corresponding value assigned to the property, this code is almost entirely copy Ms Help document. The other is displayclumcaption, which is a demo code that sets its Caption property by field name for fields in the specified table. If necessary, you can modify the SetProperty to make him a read-only function that enumerates the caption properties for each field in the specified table. In Displayclumcaption code