Using ADO`s Record Object with URLs - Exploring the Web Page URL with ADO
(Page 4 of 6 )
Type in (or Copy) the following code to the click event of the Command button. Open the file and click the button; you will see the display shown in the next picture. The text formatting was applied in the design mode.
Private Sub Command0_Click()
'Opening a Record object given the URL
Dim con As New ADODB.Connection
Dim rec As New ADODB.Record
Dim constr As String
'ConnectionString from URL.udl file's text
constr = "Provider=MSDAIPP.DSO; Data Source=http://hodentek/
TestingService/HelloOra.asmx;" & _
"Bind Flags=0;Mode=Read;Lock Owner='';Url Encoding=10;User ID=jay;" & _
"Password=;Ignore Cached Data=False; Cache Aggressively=False;" & _
"Treat As Offline=False; Mark For Offline=0;" & _
"Protocol Provider={00000000-0000-0000-0000-000000000000};" & _
"Flush WinInet Password Cache=False; User Agent string="";" & _
"Custom Http Headers="";Use Cached DAV lock Token=False;" & _
"Bypass LIS for Invoke command=False;
Dump XML response form command execution=False;" & _
"Suppress resource columns in command result=False;" & _
"Show thicket files for WEC server=False;
Redirect WinHttp to XmlHttp=False"
con.Open constr
rec.ActiveConnection = con
rec.Open
'All the properties will be stuffed into this string
Dim strPearl As String
strPearl = ""
strPearl = strPearl + "File explored is: http://hodentek/
TestingService/" & _
"HelloOra.asmx " & vbCrLf & vbCrLf
strPearl = strPearl + "Record's parent URL is: " & rec.ParentURL & _
vbCrLf & vbCrLf
strPearl = strPearl + "Now the Record's State (1 is adStateopen," & _
"0 is adStateClosed, 4 is adStateExecuting) is: " & rec.State &
vbCrLf & vbCrLf
strPearl = strPearl + "Record's Mode is (1 is adModeRead [default]): "
& _
rec.Mode & vbCrLf & vbCrLf
strPearl = strPearl + "Record's RecordType (0 is adSimpleRecord
(Leaf-node)," & _
"1 is adCollectionRecord (non-Leaf) is: " & rec.RecordType & vbCrLf &
vbCrLf
strPearl = strPearl + "Record's Source is: " & rec.Source & vbCrLf & vbCrLf
strPearl = strPearl + "Record's Fields(0) item: " & rec.Fields(0) &
vbCrLf & vbCrLf
strPearl = strPearl + "Record's Fields(1) item: " & rec.Fields(1) &
vbCrLf & vbCrLf
strPearl = strPearl + "Record's Fields(2) item: " & rec.Fields(2) &
vbCrLf & vbCrLf
strPearl = strPearl + "Number of properties for this record are : " & _
rec.Properties.Count & vbCrLf & vbCrLf
rec.Close
strPearl = strPearl + "Now the Record's State (1 is open, 0 is closed)
is: " & _
rec.State & vbCrLf
txtFile.SetFocus
txtFile.Text = strPearl
con.Close
End Sub
Once the connection string is correctly set, the derivation of the properties, or the usage of the methods is quite simple. For most of the properties the enumerated constants are used. The enumerated constants and their values are also shown for some of the properties in the above picture. For example, RecordType=0 means it is a file, whereas RecordType=1 would imply a folder. The properties explored are highlighted in the code shown above. One of the properties which distinguishes a file from a folder is the RecordType. The RecordMode property used with records is very similar to the LockType property used with recordsets. The Fields collection refers to the various parts of the URL using an index as shown in the code. In the above example, rec.Fields(0) is the HelloOra.asmx file. In order to read the content of this field you would require a Stream object.
Next: Exploring the Web Folder URL with ADO >>
More Microsoft Access Articles
More By Jayaram Krishnaswamy