Using ADO`s Record Object with URLs - Exploring the Web Folder URL with ADO
(Page 5 of 6 )
In this case we will be looking at the web folder and its contents. For this we create a form in MS Access, and place a textbox, a list box and a button. Set the properties of the list box as described in the article in the link so that the RowSource type of the ListBox is ValueList. Type in or copy the following code to the click event of the button. When the form is displayed it should look like the next picture. Some design time formatting has been applied to the controls.
Private Sub Command0_Click()
Dim con As New ADODB.Connection
Dim rec As New ADODB.Record
Dim constr As String
'This is the connection string generated by the url.udl file
constr = "Provider=MSDAIPP.DSO; Data Source=http://hodentek/Factory;" & _
"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
Dim strg As String
strg = ""
strg = strg + "The folder explored is: http://hodentek/Factory" &
vbCrLf & vbCrLf
strg = strg + "Record's parent URL is: " & rec.ParentURL & vbCrLf &
vbCrLf
strg = strg + "Record's State (1 is open, 0 is closed) is: " &
rec.State & vbCrLf & vbCrLf
strg = strg + "Record's Mode is: " & rec.Mode & vbCrLf & vbCrLf
strg = strg + "Record's RecordType (adSimpleRecord is 0;
adCollectionRecord is 1;" & _
"adStructDoc is 2) is: " & rec.RecordType & vbCrLf & vbCrLf
strg = strg + "Record's Source is: " & rec.Source & vbCrLf & vbCrLf
strg = strg + "Record's Fields(0) item: " & rec.Fields(0) & vbCrLf &
vbCrLf
strg = strg + "Record's Fields(1) item: " & rec.Fields(1) & vbCrLf &
vbCrLf
strg = strg + "Record's Fields(2) item: " & rec.Fields(2) & vbCrLf &
vbCrLf
strg = strg + "Number of properties for this record are : " &
rec.Properties.Count & vbCrLf & vbCrLf
strg = strg + "Size of GetChildren(0) is : " &
rec.GetChildren(0).ActualSize & vbCrLf & vbCrLf
Set chilun = rec.GetChildren
Do Until chilun.EOF
List3.AddItem chilun(0)
chilun.MoveNext
Loop
rec.Close strg = strg + ("Record's State (1 is open, 0 is closed)
is: " & rec.State)
Text1.SetFocus
Text1.Text = strg
con.Close End Sub
Some of the properties and methods are highlighted in the code. The important point to note is that the RecordType is 1, which refers to a collection (the sub-folders and files contained therein). The fields collection uses an index (0 based) to point to the field items.
The GetChildren() method accesses the subfolders and files in the directory, which is in this case Factory. The contents of the folder are shown in the list box with one sub-folder and several files. In order to look at the content of the individual aspx pages, you would need a Stream object.
Next: Opening the Connection with a Shorter String >>
More Microsoft Access Articles
More By Jayaram Krishnaswamy