|
The following example creates a snapshot-type Recordset object, reads each record, and displays a progress meter showing the current relative position in the snapshot.Function ReadRecords(strTableName As String) As Integer
Const conBadArgs = -1
Dim dbs As Database, rst As Recordset
Dim lngCount As Long, strMsg As String
Dim varReturn As Variant, lngX As Long
ReadRecords = 0
If strTableName <> "" Then
DoCmd.Hourglass True
Set dbs = CurrentDb
On Error Resume Next
Set rst = dbs.OpenRecordSet(strTableName)
' Get record count.
rst.MoveLast
rst.MoveFirst
If Err Then
ReadRecords = conBadArgsEnd If
lngCount = rst.RecordCount
On Error GoTo 0
If lngCount Then
strMsg = "Reading " & UCase$(strTableName) & "..."
varReturn = SysCmd(acSysCmdInitMeter, strMsg, lngCount)
' Display message in status bar.
For lngX = 1 To lngCount
varReturn = SysCmd(acSysCmdUpdateMeter, lngX)
' Update meter.
. ' Do something with record.
.
.
rst.MoveNext ' Go to next record.Next lngX
varReturn = SysCmd(acSysCmdClearStatus)
GoSub CloseObjects
ReadRecords = lngCount ' Return number of records.
Exit Function
End If
End If
' Not found or contains no records.
strMsg = "Table '" & strTableName & "'not found or contains no records.'"
MsgBox strMsg, vbInformation, "ReadRecords"
GoSub CloseObjects
Exit Function
CloseObjects:
On Error Resume Next
rst.Close
dbs.Close
On Error GoTo 0DoCmd.Hourglass False
Return
End FunctionACCESS97 都有现成的例子,[em01] |
|