SysCmd Method Example

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 = conBadArgs
        End 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 0
    DoCmd.Hourglass False
    Return
End Function

The next example illustrates how you can use the SysCmd method with the acSysCmdGetObjectState action argument to determine the state of the active database object.

Dim intObjType As Integer, strObjName As String, intObjState As Integer

intObjType = Application.CurrentObjectType
strObjName = Application.CurrentObjectName
intObjState = SysCmd(acSysCmdGetObjectState, intObjType, strObjName)
If intObjState <> 0 Then
    .
    .
    .
End If