ADO`s Stream Object - Opening a Stream using an open Record Object (Page 4 of 6 )
It is not necessary to open a recordset followed by a record to open the Stream. If you have a record already open you may just open the Stream object using that record. The record contains the Stream whose properties can be found. The following code shows how the default properties are found.
Private Sub Command0_Click()
Dim rec As New ADODB.Record
rec.Open "testing.txt", "URL=http://hodentek/"
Debug.Print "rec.Fields(2).Value: " & (rec.Fields(2).Value) & vbCrLf
Debug.Print "rec.State: "; (rec.State) & vbCrLf
'-------
Dim strm As New ADODB.stream'Item() may show index, but use this code
Set strm = rec.Fields.Item(ADODB.FieldEnum.adDefaultStream).Value
If strm.State = adStateOpen Then
Debug.Print "-------------------------" & vbCrLf
Debug.Print "Stream Open" & vbCrLf
Debug.Print "-------------------------" & vbCrLf
Debug.Print "strm.State: " & strm.State & vbCrLf
Debug.Print "strm.Type: " & strm.Type & vbCrLf
Debug.Print "strm.Size: " & strm.Size & vbCrLf
End If
strm.Close
Debug.Print "Stream Closed"
Debug.Print "-------------------------" & vbCrLf
Set strm = Nothing
'--------
rec.Close
'MsgBox (rec.State)
End Sub
The debug.print statements will give the print out of some of the values that are sought as shown in the next paragraph.
------------------------------------
rec.Fields(2).Value: http://hodentek/testing.txt
rec.State: 1
-------------------------
Stream Open
-------------------------
strm.State: 1
strm.Type: 2
strm.Size: 5271 [This is a different resource examined]
Stream Closed
-------------------------
Next: Opening a Stream using an URL reference >>
More Database Articles
More By Jayaram Krishnaswamy