ADO`s Stream Object - Syntax for opening a Stream (Page 3 of 6 )
All arguments are optional as we discussed for the memory stream syntax for opening a Stream.
Sub Open(
[Source],
[Mode As ConnectModeEnum = adModeUnknown],
[Options As StreamOpenOptionsEnum = adOpenStreamUnspecified],
[UserName As String],
[Password As String]
)
Record opens with an open recordset and Stream uses the open Record
As mentioned in the introduction, the Stream object may be opened using an open Record object. We have seen in an earlier tutorial that the Record object may open using a recordset object. This is the case we will be considering here. We look at most of the properties for this example, but we will only look at a couple of properties in other cases, as they are not going to vary.
Place a command button on an MS Access form and use the following code in the click event of the command button. The comments before the statement provide enough information to understand the code.
Private Sub Command0_Click()
'declare the there objects
Dim rec As ADODB.Record
Dim rst As ADODB.Recordset
Dim strm As ADODB.stream
'instantiate the record and recordset
Set rec = New ADODB.Record
Set rst = New ADODB.Recordset
'open recordset, must use URL= as shown
rst.Open "", "URL=http://hodentek/"
If rst.State = adStateOpen Then
MsgBox ("Recordset is Open")
End If
'use the open recordset to open the record
rec.Open rst
If rec.State = adStateOpen Then
'MsgBox ("Record is open")
End If
'instantiate the stream object
Set strm = New ADODB.stream
'open the stream using the open record
strm.Open rec, , adOpenStreamFromRecord
If strm.State = adStateOpen Then
'MsgBox ("Stream is Open")
End If
'---interrogate properties of stream--
Dim str As String
str = "---Stream Object Properties---" & vbCrLf & vbCrLf
str = str + "Stream.Charset: " & strm.Charset & vbCrLf & vbCrLf
str = str + "Stream.EOS: " & strm.EOS & vbCrLf & vbCrLf
str = str + "Stream.Line Separator: " & strm.LineSeparator & vbCrLf &
vbCrLf
str = str + "Stream.Mode: " & strm.Mode & vbCrLf & vbCrLf
str = str + "Stream.Position: " & strm.Position & vbCrLf & vbCrLf
str = str + "Stream.Size: " & strm.Size & vbCrLf & vbCrLf
str = str + "Stream.Type: " & strm.Type & vbCrLf & vbCrLf
str = str + "Stream.State: " & strm.State & vbCrLf & vbCrLf
Text1.SetFocus
Text1.Text = str
strm.Close
rec.Close
rst.Close
End Sub
While typing in the code do not forget to use the intellisense support for coding as the next picture shows while choosing what to do next. It's the multiple choice paradigm all over!

When this form is displayed we can see all the properties of the Stream object. However the values of these properties appear as numbers. These numbers are enumerated values of Constants in ADO whose description may not be available. In the drop-down cues you will find these constants. A good reference where you may find these constants listed is in the book Programming ADO (author David Sceppa; year published: 2000; ISBN: 0-7356-0764-8).

The meanings of the numeric constants are provided in the next paragraph.
|
Constants: |
Meaning: |
|
EOS: |
false means the current position in the stream is not the end. |
|
Line Separator: |
-1 means carriage return & line feed will be used in text (vbCRLF) |
|
Mode: |
1 means Read Only permission (default); there are seven such enums |
|
Position: |
0 means current position is at the beginning of data |
|
Size: |
1130, Size of the stream in bytes |
|
Type: |
type of data stored in stream, value 2 means Text (default) |
|
state: |
stream is open, or closed, 1 is open 0 is closed. |
Next: Opening a Stream using an open Record Object >>
More Database Articles
More By Jayaram Krishnaswamy