下列范例用 Internet Publishing Provider 从读/写文件夹中打开文档。Record 的 Field 对象的 Status 属性将先设置为 adFieldPendingInsert,然后更新为 adFieldOk。
sub insert()
Dim rec As New Record
' Open a read/write document
rec.Open "http://websrv/folder/subfolder", , adModeReadWrite, _
adCreateCollection Or adOpenIfExists
Debug.print "Append couple of fields"
rec.Fields.Append "chektest:fld1", adWChar, 42, adFldUpdatable, "fld1"
rec.Fields.Append "chektest:fld2", adWChar, 42, adFldUpdatable, "fld2"
Debug.Print "status for the fields"
Debug.Print rec.Fields("chektest:fld1").Status 'adfldpendinginsert
Debug.Print rec.Fields("chektest:fld2").Status 'adfldpendinginsert
rec.Fields.Update
debug.print "Update succeeds"
Debug.Print rec.Fields("chektest:fld1").Status
' adFieldOK if the update succeeds
Debug.Print rec.Fields("chektest:fld2").Status
' adFieldOK if succeeds
End sub
以下范例将从文档打开的 Record 中删除已知 Field。Status 属性将先设置为 adFieldOK,然后设置为 adFieldPendingUnknown。
sub delete() Dim rec As New Record Dim fld As Field ' Open a read/write document
rec.Open "http://websrv/folder/subfolder", , adModeReadWrite, _
adCreateCollection Or adOpenIfExists
Debug.Print rec.Fields("chektest:fld1").status ‘ should be adFldOK
' Delete a field which already exists in the collection
rec.Fields.Delete "chektest:fld1"
Set fld = rec.Fields("chektest:fld1")
Debug.Print rec.Fields("chektest:fld1").Status ' Pending delete
rec.Fields.Update
Debug.Print "Deleted"
Debug.Print fld.Status ' Pending unknown
End sub
下列代码将从只读文档上打开的 Record 中删除 Field。Status 将设置为 adFieldPendingDelete。在 Update 时,删除失败并且 Status 为 adFieldPendingDelete 和 adFieldPermissionDenied 之和。CancelUpdate 清除挂起的 Status 设置。
sub delete2()
Dim rec As New Record Dim fld As Field ' Open a read/write document
rec.Open "http://websrv/folder/subfolder", , adModeReadWrite, _
adCreateCollection Or adOpenIfExists
Debug.Print "Try to delete something without permission"
rec.Fields.Delete ("RESOURCE_PARSENAME")
Set fld = rec.Fields("RESOURCE_PARSENAME")
Debug.Print "Pending delete"
Debug.Print fld.Status ' Pending delete
Debug.Print "Delete should fail on Update"
rec.Fields.Update ' Should fail
Debug.Print fld.Status ' Pending delete plus error
rec.Fields.CancelUpdate
Debug.Print fld.Status ' Okay
End sub