ADO 2.5 Samples

Status Property Example (Field) (VB)

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 Main()
    
   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://MyServer/"
   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 Main()

   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://MyServer/"
   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.

Sub Main()
   Dim File As ADODB.Record
   Dim fld As ADODB.Field
   Dim Cnxn As ADODB.Connection
   Dim strCnxn As String
   Dim strFile As String
   
    ' create connection as a URL
   Set Cnxn = New ADODB.Connection
   strCnxn = "url=http://MyServer/"
   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

See Also

Field Object | Record Object | Status Property (ADO Field)

© 1998-2003 Microsoft Corporation. All rights reserved.