Size, Type Properties Example

This example copies to Sheet1 all fields of the Double type from Orders.dbf, a dBASE IV table located in the C:\Program Files\Microsoft Office\Office folder.

Dim db As Database, recordsToCopy As Recordset, tDef As Recordset
Dim fieldsToStore(100), fileName As String
fileName = "ORDERS.DBF"
Set db = Workspaces(0) _
    .OpenDatabase("C:\Program Files\Microsoft Office\Office", _
    False, False, "dBASE IV")
Set tDef = db.OpenRecordset(fileName)
n = 0
Sheets("Sheet1").Activate
For Each fld In tDef.Fields
    If fld.Type = dbDouble Then
        fieldsToStore(n) = fld.Name
        n = n + 1
    End If
Next
If fieldsToStore(0) = "" Then
    MsgBox "There are no number fields in this table."
    Exit Sub
End If
For i = 0 To n - 1
    records = "SELECT " & "[" & fieldsToStore(i) & "]" _
        & " from " & db.Recordsets(fileName).Name & ";"
    Set recordsToCopy = db.OpenRecordset(records)
    With ActiveSheet.Cells(1, i + 1)
        .CopyFromRecordset recordsToCopy
        .ColumnWidth = recordsToCopy.Fields(0).Size
    End With
Next
recordsToCopy.Close
tDef.Close
db.Close