How to check in


This sample attempts to check in all transactions in the ArcPad transaction log. This sample demonstrates how to use the IAPTransLog and IAPTransLogInfo members.

How to use

  1. Open ArcMap.
  2. Add geodatabase layers that have been checked out for ArcPad.
  3. Start an editing session.
  4. Paste the code into VBA and run the macro.
[VBA]
Public Sub CheckIn()
    On Error GoTo ErrorHandler
    '++ get a reference to the ArcPad Extension
    Dim pAPExtension As IArcPadExtension
    Dim pID As New UID
    pID = "editorExt.ArcPadExtension"
    Set pAPExtension = Application.FindExtensionByCLSID(pID)
    
    '++ ArcPad xfer error vars
    Dim lErrorNum As Long
    Dim sErrorDesc As String
    
    '++ get a reference to the Transaction log
    Dim pTransLog As IAPTransLog
    Dim pTransLogInfo As IAPTransLogInfo
    Dim pAPTrans As IArcPadTransaction
    Set pTransLog = pAPExtension.Log
    Set pTransLogInfo = pTransLog 'QI
    Set pAPTrans = pAPExtension 'QI
    
    '++ log entry vars
    Dim sCheckoutName As String, sSrcVersion As String, sFldMapping As String
    Dim sSrcField As String, sStatusField As String
    Dim pSrcFCName As IName, pCheckoutFCName As IName
    Dim dtCheckoutDate As Variant
    Dim arrFIDList() As Long
    
    '++ loop through log while there are entries left to deal with
    Dim iCount As Integer
    Dim lCounter As Long
    Dim lStatusFld As Long
    Dim pCheckoutFC As IFeatureClass
    Dim pDatasetName As IDatasetName
    Dim sSrcFCName As String
    Dim pFeat As IFeature
    Dim lNoChange As Long, lAttChange As Long, lGeomChange As Long, lNewFeat As Long, lDeleted As Long
    
    lCounter = 0
    Do While ((pTransLogInfo.Count > 0) And (lCounter < pTransLogInfo.Count))
        '++ reset running tallys
        lNoChange = 0
        lAttChange = 0
        lGeomChange = 0
        lNewFeat = 0
        lDeleted = 0
        
        '++ get the log entry
        arrFIDList = pTransLogInfo.FIDList(lCounter)
        Call pTransLogInfo.Entry(lCounter, sCheckoutName, pSrcFCName, sSrcVersion, pCheckoutFCName, sFldMapping, sSrcField, sStatusField, dtCheckoutDate)
        
        '++ get the checkout FC
        Set pCheckoutFC = OpenFeatureClass(pCheckoutFCName)
        
        '++ if error getting the FC, skip it
        If pCheckoutFC Is Nothing Then
            lCounter = lCounter + 1
            '++ otherwise...
        Else
            '++ get the status field
            lStatusFld = pCheckoutFC.FindField(sStatusField)
            '++ loop through all features and tally the status
            For iCount = 0 To (pCheckoutFC.FeatureCount(Nothing) - 1)
                Set pFeat = pCheckoutFC.GetFeature(iCount)
                
                Select Case pFeat.Value(lStatusFld)
                    Case 0
                        lNoChange = lNoChange + 1
                    Case 1
                        lNewFeat = lNewFeat + 1
                    Case 2
                        lAttChange = lAttChange + 1
                    Case 3
                        lGeomChange = lGeomChange + 1
                End Select
            Next
            lDeleted = ((UBound(arrFIDList) + 1) + lNewFeat) - iCount
            
            '++ get the name of the feature class
            Set pDatasetName = pSrcFCName
            sSrcFCName = pDatasetName.Name
            
            '++ report the status
            MsgBox "No change: " & lNoChange & vbCrLf & _
                "New Ftr: " & lNewFeat & vbCrLf & _
                "Att change: " & lAttChange & vbCrLf & _
                "Geometry change: " & lGeomChange & vbCrLf & _
                "Deleted: " & lDeleted, vbInformation, sSrcFCName
            
            '++ attempt to check in
            pAPTrans.CheckinFeatures pCheckoutFCName
            Select Case lErrorNum
Case 0:
                Call pTransLog.CheckIn(pCheckoutFCName, sSrcVersion)
                pTransLog.SaveLogInformation
                MsgBox "Successfully checked in " & sSrcFCName, vbInformation, sSrcFCName
Case Else:
                MsgBox "Cannot check in " & sSrcFCName & "." & _
                    vbCrLf & sErrorDesc, vbCritical, sSrcFCName
                lErrorNum = 0
                lCounter = lCounter + 1
            End Select
        End If
    Loop
    Exit Sub
    
ErrorHandler:
    Select Case Err.Number
        '++ handle ArcPad xfer errors
Case -2147221247 To -2147221242:
        lErrorNum = Err.Number
        sErrorDesc = Err.Description
        Resume Next
        '++ handle all other errors
Case Else:
        MsgBox Err.Number & vbCrLf & Err.Description, vbCritical, "Error"
    End Select
End Sub

Function OpenFeatureClass(pFCName As IName) As IFeatureClass
    On Error Resume Next
    Set OpenFeatureClass = pFCName.Open
    If Err.Number <> 0 Then Set OpenFeatureClass = Nothing
End Function