Microsoft ActiveX Data ObjectsMicrosoft ActiveX Data Objects*
*Contents  *Index  *Topic Contents

Type Property Example

This example demonstrates the Type property by displaying the name of the constant corresponding to the value of the Type property of all the Field objects in the Employee table. The FieldType function is required for this procedure to run.

Public Sub TypeX()

	Dim rstEmployees As ADODB.Recordset
	Dim fldLoop As ADODB.Field
	Dim strCnn As String

	' Open recordset with data from Employee table.
	strCnn = "driver={SQL Server};server=srv;" & _
		"uid=sa;pwd=;database=pubs"
	Set rstEmployees = New ADODB.Recordset
	rstEmployees.Open "employee", strCnn, , , adCmdTable

	Debug.Print "Fields in Employee Table:" & vbCr

	' Enumerate Fields collection of Employees table.
	For Each fldLoop In rstEmployees.Fields
		Debug.Print "    Name: " & fldLoop.Name & vbCr & _
			"    Type: " & FieldType(fldLoop.Type) & vbCr
	Next fldLoop

End Sub

Public Function FieldType(intType As Integer) As String

	Select Case intType
		Case adChar
			FieldType = "adChar"
		Case adVarChar
			FieldType = "adVarChar"
		Case adSmallInt
			FieldType = "adSmallInt"
		Case adUnsignedTinyInt
			FieldType = "adUnsignedTinyInt"
		Case adDBTimeStamp
			FieldType = "adDBTimeStamp"
	End Select

End Function

Up Top of Page
© 1997 Microsoft Corporation. All rights reserved. Terms of Use.