D
doswald4
I'm using the following function to find the size of a table. Can anyone
offer any hints on why it fails, or offer an easier way to find table size?
Details: It works fine in Access 2000 but when I try to run the same db in
Access 2003, it throws an error at the marked statement. At the end, if I
stop the procedure, ECode gets set to 13, which I think is a Type Mismatch.
'--------------------------------------
Function TableRecords(tablename As String) As Long
On Error GoTo Err_TableRecords
'Passed table name, returns number of records in that table
' or 0 if error
Dim MyDatabase As Database
Dim MyTable As Recordset
Dim ECode as Variant
'Set default return value
'TableRecords = 0
'Open myself
Set MyDatabase = OpenDatabase(Application.CurrentDb.Name)
mydbname = MyDatabase.Name
With MyDatabase
' Open table-type Recordset
Set MyTable = .OpenRecordset(tablename) '***THIS STATEMENT FAILS***
'Move to last record
MyTable.MoveLast
'capture no. of records
TableRecords = MyTable.RecordCount
Exit_TableRecords:
'close the recordset
MyTable.Close
'close database
.Close
End With
Exit Function
Err_TableRecords:
ECode = Err
TableRecords = 0
GoTo Exit_TableRecords
End Function
offer any hints on why it fails, or offer an easier way to find table size?
Details: It works fine in Access 2000 but when I try to run the same db in
Access 2003, it throws an error at the marked statement. At the end, if I
stop the procedure, ECode gets set to 13, which I think is a Type Mismatch.
'--------------------------------------
Function TableRecords(tablename As String) As Long
On Error GoTo Err_TableRecords
'Passed table name, returns number of records in that table
' or 0 if error
Dim MyDatabase As Database
Dim MyTable As Recordset
Dim ECode as Variant
'Set default return value
'TableRecords = 0
'Open myself
Set MyDatabase = OpenDatabase(Application.CurrentDb.Name)
mydbname = MyDatabase.Name
With MyDatabase
' Open table-type Recordset
Set MyTable = .OpenRecordset(tablename) '***THIS STATEMENT FAILS***
'Move to last record
MyTable.MoveLast
'capture no. of records
TableRecords = MyTable.RecordCount
Exit_TableRecords:
'close the recordset
MyTable.Close
'close database
.Close
End With
Exit Function
Err_TableRecords:
ECode = Err
TableRecords = 0
GoTo Exit_TableRecords
End Function