This example uses the ActualSize and DefinedSize properties to display the defined size and actual size of a field.
'BeginActualSizeVB
'To integrate this code
'replace the data source and initial catalog values
'in the connection string
Public Sub ActualSizeX()
'recordset and connection variables
Dim rstStores As ADODB.Recordset
Dim Cnxn As ADODB.Connection
Dim SQLStores As String
Dim strCnxn As String
'record variables
Dim strMessage As String
' Open a recordset for the Stores table
strCnxn = "Provider=sqloledb;Data Source=MyServer;Initial Catalog=Northwind;User Id=sa;Password=; "
Set rstStores = New ADODB.Recordset
SQLStores = "Suppliers"
'rstStores.Open SQLStores, strCnx, , , adCmdTable
rstStores.Open SQLStores, strCnx, adOpenForwardOnly, adLockReadOnly, adCmdTable
'the above two lines of code are identical as the default values for
'CursorType and LockType arguments match those indicated
' Loop through the recordset displaying the contents
' of the store_name field, the field's defined size,
' and its actual size.
rstStores.MoveFirst
Do Until rstStores.EOF
strMessage = "Company name: " & rstStores!CompanyName & _
vbCrLf & "Defined size: " & _
rstStores!CompanyName.DefinedSize & _
vbCrLf & "Actual size: " & _
rstStores!CompanyName.ActualSize & vbCrLf
MsgBox strMessage, vbOKCancel, "ADO ActualSize Property (Visual Basic)"
rstStores.MoveNext
Loop
' clean up
rstStores.Close
Cnxn.Close
Set rstStores = Nothing
Set Cnxn = Nothing
End Sub
'EndActualSizeVB
ActualSize Property | DefinedSize Property | Field Object
© 1998-2001 Microsoft Corporation. All rights reserved.