The following example opens a document from a read/write folder using the Internet Publishing Provider. The Status property of a Field object of the Record will first be set to adFieldPendingInsert, then be updated to adFieldOk.
'BeginStatusFieldVB
' to integrate this code replace the values in the source string
Sub insert()
Dim File As ADODB.Record
Dim strFile As String
Dim Cnxn As ADODB.Connection
Dim strCnxn As String
Set Cnxn = New ADODB.Connection
strCnxn = "" '"url=http://ServerName/"
Cnxn.Open strCnxn
Set File = New ADODB.Record
strFile = "" '"Folder/FileName"
' Open a read/write document
File.Source = strFile
File.ActiveConnection = Cnxn
File.Mode = adModeReadWrite
File.Open
Debug.Print "Append a couple of fields"
File.fields.Append "chektest:fld1", adWChar, 42, adFldUpdatable, "fld1"
File.fields.Append "chektest:fld2", adWChar, 42, adFldUpdatable, "fld2"
Debug.Print "status for the fields"
Debug.Print File.fields("chektest:fld1").Status 'adfldpendinginsert
Debug.Print File.fields("chektest:fld2").Status 'adfldpendinginsert
'turn off error-handling to verify field status
On Error Resume Next
File.fields.Update
Debug.Print "Update succeeds"
Debug.Print File.fields("chektest:fld1").Status 'adfldpendinginsert + adFieldUnavailable
Debug.Print File.fields("chektest:fld2").Status 'adfldpendinginsert + adFieldUnavailable
' resume default error-handling
On Error GoTo 0
' clean up
File.Close
Cnxn.Close
Set File = Nothing
Set Cnxn = Nothing
End Sub
'EndStatusFieldVB
The following example deletes a known Field from a Record opened from a document. The Status property will first be set to adFieldOK, then adFieldPendingUnknown.
'BeginStatusField2VB
' to integrate this code replace the values in the source string
Sub delete()
Dim File As ADODB.Record
Dim fld As ADODB.Field
Dim strFile As String
Dim Cnxn As ADODB.Connection
Dim strCnxn As String
' create connection as a URL
Set Cnxn = New ADODB.Connection
strCnxn = "" '"url=http://ServerName/"
Cnxn.Open strCnxn
Set File = New ADODB.Record
strFile = "" '"Folder/FileName"
' Open a read/write document
File.Open strFile, Cnxn, adModeReadWrite
Debug.Print File.fields("chektest:fld1").Status ' should be adFldOK
' Delete a field which already exists in the collection
File.fields.delete "chektest:fld1"
Set fld = File.fields("chektest:fld1")
Debug.Print File.fields("chektest:fld1").Status ' Pending delete
'turn off error-handling to verify field status
On Error Resume Next
File.fields.Update
Debug.Print "Deleted"
Debug.Print fld.Status ' Pending unknown
' resume default error-handling
On Error GoTo 0
' clean up
File.Close
Cnxn.Close
Set File = Nothing
Set Cnxn = Nothing
End Sub
'EndStatusField2VB
The following code deletes a Field from a Record opened on a read-only document. Status will be set to adFieldPendingDelete. At Update, the delete will fail and Status will be adFieldPendingDelete plus adFieldPermissionDenied. CancelUpdate clears the pending Status setting.
'BeginStatusField3VB
Sub delete2()
Dim File As ADODB.Record
Dim fld As ADODB.Field
Dim Cnxn As ADODB.Connection
Dim strCnxn As String
' create connection as a URL
Set Cnxn = New ADODB.Connection
strCnxn = "" '"url=http://ServerName/"
Cnxn.Open strCnxn
' Open a read/write document
Set File = New ADODB.Record
strFile = "" '"Folder/FileName"
File.Open strFile, Cnxn, adModeReadWrite, adCreateCollection Or adOpenIfExists
Debug.Print "Try to delete something without permission"
File.fields.delete ("RESOURCE_PARSENAME")
Set fld = File.fields("RESOURCE_PARSENAME")
Debug.Print "Pending delete"
Debug.Print fld.Status ' Pending delete
Debug.Print "Delete should fail on Update"
'turn off error-handling to verify field status
On Error Resume Next
File.fields.Update ' Should fail
Debug.Print fld.Status ' Pending delete plus error
File.fields.CancelUpdate
Debug.Print fld.Status ' Okay
' resume default error-handling
On Error GoTo 0
' clean up
File.Close
Cnxn.Close
Set File = Nothing
Set Cnxn = Nothing
End Sub
'EndStatusField3VB
Field Object | Record Object | Status Property (ADO Field)
© 1998-2001 Microsoft Corporation. All rights reserved.