Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Como se ve el tamaño de las tablas en una base de datos de ACCESS

517 views
Skip to first unread message

Mery

unread,
Apr 12, 2010, 6:24:01 AM4/12/10
to
Quisiera saber la forma de ver el tamaño de las tablas de una base de datos
en ACCESS 2007.

Emilio

unread,
Apr 12, 2010, 7:03:01 AM4/12/10
to
Hola!

No se puede saber el tamaño de una tabla, se puede calcular de manera
apróximada mediante código:

'*******************************************************************************
'* TamañoTabla
'* Calcula el tamaño de la tabla pasada como parámetro
'* Argumentos: strTabla => Nombre de la tabla
'* uso: TamañoTabla "Pedidos"
'* Si utilizas este código, respeta la autoría y los créditos
'* ESH 26/02/06 09:49
'*******************************************************************************

Public Function TamañoTabla(strTabla As String) As Long
Dim Campo As Object, _
rst As DAO.Recordset, _
strSQL As String, _
Matriz() As Variant, _
i As Long, _
lngCuenta As Long, _
lngTamaño As Long

On Error GoTo TamañoTabla_TratamientoErrores

strSQL = "SELECT * FROM " & strTabla

Set rst = CurrentDb.OpenRecordset(strSQL, dbopendynaset)

rst.MoveLast

lngCuenta = rst.RecordCount

For Each Campo In rst.Fields
ReDim Preserve Matriz(2, i)
Matriz(0, i) = Campo.Name
Matriz(1, i) = Campo.Type
' según el tipo de campo calculo el tamaño ocupado como el producto
' del número de registros por su correspondiente tamaño en bits
Select Case Campo.Type
Case dbBoolean ' 1 bit
Matriz(2, i) = lngCuenta * 1
Case dbByte ' 1 byte
Matriz(2, i) = lngCuenta * 8
Case dbCurrency, dbDate, dbDouble ' 8 bytes
Matriz(2, i) = lngCuenta * 64
Case dbSingle, dbLong ' 4 bytes
Matriz(2, i) = lngCuenta * 32
Case dbInteger ' 2 bytes
Matriz(2, i) = lngCuenta * 16
End Select
i = i + 1
Next Campo

For i = 0 To UBound(Matriz, 2)
' acumulo el tamaño de todos los campos, para el caso de los
' campos texto y memo, recorro registro por registro y acumulo
' su longitud multiplicada por 8 para convertirla a bits
If Matriz(1, i) = dbText Or Matriz(1, i) = dbMemo Then
rst.MoveFirst
Do While Not rst.EOF
lngTamaño = lngTamaño + Nz(Len(rst(Matriz(O, i))), 0) * 8
rst.MoveNext
Loop
Else
lngTamaño = lngTamaño + Matriz(2, i)
End If
Next i
' devuelvo el tamaño convertido a bytes
TamañoTabla = lngTamaño / 8

If Not rst Is Nothing Then
rst.Close
Set rst = Nothing
End If

TamañoTabla_Salir:
On Error GoTo 0
Exit Function

TamañoTabla_TratamientoErrores:

MsgBox "Error " & Err.Number & " en proc.: TamañoTabla de Documento VBA:
Form_frmTamaño (" & Err.Description & ")"
Resume TamañoTabla_Salir
End Function ' TamañoTabla

Saludos a todos desde Huelva

Emilio [MS-MVP Access 2006/10]
miliuco56 ALGARROBA hotmail PUNTO com
http://www.mvp-access.com/foro
http://www.mvp-access.es/emilio


"Mery" escribió:

0 new messages