Sub SetProperty(dbsTemp As DAO.Field, strName As String, _ booTemp As String) Dim prpNew As DAO.Property Dim errLoop As Error ' Attempt to set the specified property. On Error GoTo Err_Property dbsTemp.Properties(strName) = booTemp On Error GoTo 0 Exit Sub Err_Property: ' Error 3270 means that the property was not found. If DBEngine.Errors(0).Number = 3270 Then ' Create property, set its value, and append it to the ' Properties collection. Set prpNew = dbsTemp.CreateProperty(strName, _ dbText, booTemp) dbsTemp.Properties.Append prpNew Resume Next Else ' If different error has occurred, display message. For Each errLoop In DBEngine.Errors MsgBox "Error number: " & errLoop.Number & vbCr & _ errLoop.Description Next errLoop End End If End Sub Sub DisplayClumCaption(ByVal tbname As String, ByVal fldIndex As Integer) Dim dset As DAO.TableDef) //*****必须使用TableDef对象 Dim i As Integer Dim tmpProp As DAO.Property //强制使用DAO类型 Dim fld As DAO.Field //强制使用DAO类型 Dim tmpTxt As String 'On Error Resume Next Dim msg As String Dim cdb As DAO.Database //*****强制使用DAO类型 Set cdb = CurrentDb //****关键,确定对当前数据库的静态引用 Set dset = cdb.TableDefs(tbname)//*****必须使用TableDef对象 For Each fld In dset.Fields tmpTxt = fld.Name SetProperty fld, "Caption", tmpTxt msg = msg + fld.Properties("Caption") msg = msg + Chr(10) + Chr(13)