<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Download table data by Microsoft Access in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/download-table-data-by-microsoft-access/m-p/3197663#M762003</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I developed the script to which all records of the table were downloaded by the macro of Microsoft Access.&lt;/P&gt;&lt;P&gt;It builds it in according to the following procedures.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Create Empty new access file.&lt;/P&gt;&lt;P&gt;2. Create new module.&lt;/P&gt;&lt;P&gt;3. Copy &amp;amp; Paste following VBA code.&lt;/P&gt;&lt;P&gt;4. Select "Tool" -&amp;gt; "Reference setting". Check on to "Microsoft ADO Ext. 2.8 for DDL and Security"&lt;/P&gt;&lt;P&gt;5. Save module.&lt;/P&gt;&lt;P&gt;6. Create new macro. Select "Execute procedure" and input procedure name "testConnect()".&lt;/P&gt;&lt;P&gt;7. Execute macro, and  follow the prompt and have FUN!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
'*----------------------------------------------------------------------*
'*  Program Name : SAP Table Data Downloader
'*  Created on : 2007/11/28      Author : Nobubyoshi Kikuchi(ABeam)
'*----------------------------------------------------------------------*
'*  Updated on : yyyy/mm/dd      Author :
'*  Request for change No :
'*  Remarks :
'*----------------------------------------------------------------------*

' Public Constant Definition ======================================================*
Public Const C_RFCNAME_READTABLE        As String = "RFC_READ_TABLE"
Public Const C_RFCPARA_FIELDS           As String = "FIELDS"
Public Const C_RFCPARA_DATA             As String = "DATA"
Public Const C_RFCPARA_COL_FIELDNAME    As String = "FIELDNAME"
Public Const C_RFCPARA_COL_OFFSET       As String = "OFFSET"
Public Const C_RFCPARA_COL_LENGTH       As String = "LENGTH"
Public Const C_RFCPARA_COL_TYPE         As String = "TYPE"
Public Const C_RFCPARA_COL_FIELDTEXT    As String = "FIELDTEXT"
Public Const C_RFCPARA_COL_VALUE        As String = "WA"
Public Const C_RFCPARA_QUERY_TABLE      As String = "QUERY_TABLE"
Public Const C_RFCPARA_DELIMITER        As String = "DELIMITER"
Public Const C_RFCPARA_NO_DATA          As String = "NO_DATA"
Public Const C_RFCPARA_ROWSKIPS         As String = "ROWSKIPS"
Public Const C_RFCPARA_ROWCOUNT         As String = "ROWCOUNT"
Public Const C_PROGRESS_MSG_01          As String = "Creating SAP Connection (1/5)"
Public Const C_PROGRESS_MSG_02          As String = "Getting table fields information (2/5)"
Public Const C_PROGRESS_MSG_03          As String = "Creating table at MS-Access (3/5)"
Public Const C_PROGRESS_MSG_04          As String = "Reading table data (4/5)"
Public Const C_PROGRESS_MSG_05          As String = "Appending data (5/5)"
Public Const C_PROGRESS_MSG_99          As String = " "
Public Const C_SAP_FUNCTION_CLASS       As String = "SAP.Functions"


'*&amp;amp;---------------------------------------------------------------------*
'*&amp;amp;      testConnect
'*&amp;amp;---------------------------------------------------------------------*
'*       This function
'*----------------------------------------------------------------------*
'*       &amp;lt;Non paramente&amp;gt;
'*----------------------------------------------------------------------*
Public Function testConnect()

    Dim sTableName As String
    
    sTableName = InputBox("Import table name")

    createReadTable (sTableName)

End Function

'*&amp;amp;---------------------------------------------------------------------*
'*&amp;amp;      createReadTable
'*&amp;amp;---------------------------------------------------------------------*
'*       1.Connect to SAP
'*       2.Get table fileds information
'*       3.Create table in MS-Access
'*       4.Read table data from SAP table
'*       5.Append data to MS-Access table
'*----------------------------------------------------------------------*
'*       --&amp;gt;sTableName      Read table name
'*----------------------------------------------------------------------*
Public Function createReadTable(sTableName As String)

   On Error GoTo eHandler

' Data Definition ======================================================*
    
    Dim oSAP            As Object           'SAP object
    Dim oConnection     As Object           'SAP Connection object
    Dim oFields         As Collection       'Table fields collection
    Dim oData           As Collection       'Table data collection

    Set oFields = New Collection
    Set oData = New Collection
    
' Process ==============================================================*

    'Check table name
    If sTableName = Empty Then
        MsgBox "Please input table name"
        Exit Function
    End If

    'Create SAP connection
    SysCmd acSysCmdSetStatus, C_PROGRESS_MSG_01
    If createConnection(oSAP, oConnection) = False Then
        Exit Function
    End If

    'Get table fields
    SysCmd acSysCmdSetStatus, C_PROGRESS_MSG_02
    If getTableFields(oSAP, oFields, sTableName) = False Then
        Exit Function
    End If

    'Create table at MS-Access
    SysCmd acSysCmdSetStatus, C_PROGRESS_MSG_03
    If createTable(oFields, sTableName) = False Then
        Exit Function
    End If

    'Read table data
    SysCmd acSysCmdSetStatus, C_PROGRESS_MSG_04
    If readTableData(oSAP, oFields, sTableName, oData) = False Then
        Exit Function
    End If

    'Append data
    SysCmd acSysCmdSetStatus, C_PROGRESS_MSG_05
    If appendData(oFields, oData, sTableName) = False Then
        Exit Function
    End If

    SysCmd acSysCmdSetStatus, C_PROGRESS_MSG_99
    
' Terminate ===========================================================*
    Set oFields = Nothing
    Set oData = Nothing
    Set oConnection = Nothing
    Set oSAP = Nothing
    
    Exit Function

eHandler:
    MsgBox "System Error : " &amp;amp; Err.Number &amp;amp; " " &amp;amp; Err.Description &amp;amp; "(" &amp;amp; Err.Source &amp;amp; ")"
    Exit Function
End Function

'*&amp;amp;---------------------------------------------------------------------*
'*&amp;amp;      createConnection
'*&amp;amp;---------------------------------------------------------------------*
'*       Connect to SAP (Not Silent Logon)
'*----------------------------------------------------------------------*
'*       &amp;lt;--oSAP            SAP object
'*       &amp;lt;--oConnection     Connection object
'*----------------------------------------------------------------------*
Private Function createConnection(oSAP As Object, oConnection As Object) As Boolean

    'Set return value
    createConnection = False

    'Create SAP instance
    Set oSAP = CreateObject(C_SAP_FUNCTION_CLASS)
    'Create SAP connection
    Set oConnection = oSAP.Connection

    'Logon information(Using silent logon)
    'oConnection.Applicationserver = "XXX.XXX.XXX.XXX"
    'oConnection.Client = "XXX"
    'oConnection.user = "XXXXXXXXX"
    'oConnection.language = "J"
    'oConnection.password = "XXXXXXX"
    
    'SAP logon (if you want silent logon, change FALSE to TRUE)
    If oConnection.logon(0, False) &amp;lt;&amp;gt; True Then
        MsgBox "Logon failure"
        Exit Function
    End If
    
    'Set return value
    createConnection = True
    
End Function

'*&amp;amp;---------------------------------------------------------------------*
'*&amp;amp;      getTableFields
'*&amp;amp;---------------------------------------------------------------------*
'*       Get table fields information
'*----------------------------------------------------------------------*
'*       --&amp;gt;oSAP            SAP object
'*       &amp;lt;--oFields         Table fields information
'*       --&amp;gt;sTableName      Read table name
'*----------------------------------------------------------------------*
Private Function getTableFields(oSAP As Object, oFields As Collection, sTableName As String) As Boolean

    'Set return value
    getTableFields = False

' Data Definition ======================================================*
    Dim oFunctionmodule As Object       'SAP Function module object
    Dim oTempFields     As Object       'Temporary object
    Dim row             As Object       'Table row object

' Process ==============================================================*
    'Create remote function module instance
    Set oFunctionmodule = oSAP.Add(C_RFCNAME_READTABLE)
    
    'Set function module parameters
    oFunctionmodule.exports(C_RFCPARA_QUERY_TABLE) = sTableName
    oFunctionmodule.exports(C_RFCPARA_DELIMITER) = ""
    oFunctionmodule.exports(C_RFCPARA_NO_DATA) = "X"
    oFunctionmodule.exports(C_RFCPARA_ROWSKIPS) = 0
    oFunctionmodule.exports(C_RFCPARA_ROWCOUNT) = 0
    
    'Call remote function modele
    oFunctionmodule.Call
    If oFunctionmodule.Exception &amp;lt;&amp;gt; "" Then
        MsgBox ("Error of function module call:" &amp;amp; oFunctionmodule.Exception)
        Exit Function
    End If
    
    'Get table fields information
    Set oTempFields = oFunctionmodule.Tables(C_RFCPARA_FIELDS)
    For Each row In oTempFields.Rows
        Set oField = New Collection
        oField.Add Item:=row.Value(C_RFCPARA_COL_FIELDNAME), Key:=C_RFCPARA_COL_FIELDNAME
        oField.Add Item:=row.Value(C_RFCPARA_COL_OFFSET), Key:=C_RFCPARA_COL_OFFSET
        oField.Add Item:=row.Value(C_RFCPARA_COL_LENGTH), Key:=C_RFCPARA_COL_LENGTH
        oField.Add Item:=row.Value(C_RFCPARA_COL_TYPE), Key:=C_RFCPARA_COL_TYPE
        oField.Add Item:=row.Value(C_RFCPARA_COL_FIELDTEXT), Key:=C_RFCPARA_COL_FIELDTEXT
        oFields.Add oField
    Next row

' Terminate ===========================================================*
    Set oTempFields = Nothing

    'Set return value
    getTableFields = True

End Function

'*&amp;amp;---------------------------------------------------------------------*
'*&amp;amp;      createTable
'*&amp;amp;---------------------------------------------------------------------*
'*       Create table in MS-Access
'*----------------------------------------------------------------------*
'*       --&amp;gt;oFields         Table fields information
'*       --&amp;gt;sTableName      Read table name
'*----------------------------------------------------------------------*
Private Function createTable(oFields As Collection, sTableName As String) As Boolean

    'Set return value
    createTable = False

' Data Definition ======================================================*
    Dim catalog         As ADOX.catalog     'Catalog object
    Dim table           As ADOX.table       'Table object
    Dim row             As Collection       'Table row object
    
' Process ==============================================================*
    'Create and Activetion current project instance
    Set catalog = New ADOX.catalog
    catalog.ActiveConnection = CurrentProject.Connection

    'Clear import table
    For Each table In catalog.Tables
        If sTableName = table.Name Then
            catalog.Tables.Delete sTableName
        End If
    Next table
    Set table = Nothing

    'Create table instance
    Set table = New ADOX.table
    table.Name = sTableName
    
    'Define table fileds
    For Each row In oFields
               
        'Append columns by types
        Select Case row.Item(C_RFCPARA_COL_TYPE)
            Case "C"    'Char
                table.Columns.Append row.Item(C_RFCPARA_COL_FIELDNAME), adVarWChar
            Case "D", "T"   'Date and Time
                table.Columns.Append row.Item(C_RFCPARA_COL_FIELDNAME), adVarWChar
            Case "P"    '
                table.Columns.Append row.Item(C_RFCPARA_COL_FIELDNAME), adDouble
            Case Else
                table.Columns.Append row.Item(C_RFCPARA_COL_FIELDNAME), adVarWChar
        End Select
        
        'Set nullable attribute
        table.Columns(row.Item(C_RFCPARA_COL_FIELDNAME)).Attributes = adColNullable
        
    Next row
    
    'Append table to catalog
    catalog.Tables.Append table
    
' Terminate ===========================================================*
    Set catalog = Nothing
    Set table = Nothing

    'Set return value
    createTable = True

End Function

'*&amp;amp;---------------------------------------------------------------------*
'*&amp;amp;      readTableData
'*&amp;amp;---------------------------------------------------------------------*
'*       Read SAP table data
'*----------------------------------------------------------------------*
'*       --&amp;gt;oSAP            SAP object
'*       --&amp;gt;oFields         Table fields information
'*       --&amp;gt;sTableName      Read table name
'*       &amp;lt;--oData           Read table data
'*----------------------------------------------------------------------*
Private Function readTableData(oSAP As Object, oFields As Collection, sTableName As String, oData As Collection) As Boolean

    'Set return value
    readTableData = False

' Data Definition ======================================================*
    Dim iLength         As Integer
    Dim row             As Collection   'Table row object
    Dim oFieldsTable    As Object
    Dim oFunctionmodule As Object       'SAP Function module object

    Set oFunctionmodule = Nothing

' Process ==============================================================*
    'Create remote function module instance
    Set oFunctionmodule = oSAP.Add(C_RFCNAME_READTABLE)
    
    'Set function module parameters
    oFunctionmodule.exports(C_RFCPARA_QUERY_TABLE) = sTableName
    oFunctionmodule.exports(C_RFCPARA_DELIMITER) = ""
    oFunctionmodule.exports(C_RFCPARA_NO_DATA) = ""     'I want data!!
    oFunctionmodule.exports(C_RFCPARA_ROWSKIPS) = 0
    oFunctionmodule.exports(C_RFCPARA_ROWCOUNT) = 0

    'Create FIELDS table parameter object
    Set oFieldsTable = oFunctionmodule.Tables(C_RFCPARA_FIELDS)
    
    'Initialize
    oFieldsTable.FreeTable
    iLength = 0
        
    'Set import parameter and Call function
    For Each row In oFields

        'Calls every 512 bytes (The limit of RFC_READ_TABLE)
        iLength = iLength + row.Item(C_RFCPARA_COL_LENGTH)
        If iLength &amp;lt;= 512 Then
        
            oFieldsTable.Rows.Add
            oFieldsTable(oFieldsTable.RowCount, C_RFCPARA_COL_FIELDNAME) = row.Item(C_RFCPARA_COL_FIELDNAME)
        
        Else
            'Call remote function module
            If callFunction(oFunctionmodule, oFieldsTable, oData) = False Then
                Exit Function
            End If
            oFieldsTable.FreeTable
            iLength = row.Item(C_RFCPARA_COL_LENGTH)
            oFieldsTable.Rows.Add
            oFieldsTable(oFieldsTable.RowCount, C_RFCPARA_COL_FIELDNAME) = row.Item(C_RFCPARA_COL_FIELDNAME)
        End If

    Next row

    'Call remote function module
    If callFunction(oFunctionmodule, oFieldsTable, oData) = False Then
        Exit Function
    End If
    
    'Set return value
    readTableData = True


End Function

'*&amp;amp;---------------------------------------------------------------------*
'*&amp;amp;      callFunction
'*&amp;amp;---------------------------------------------------------------------*
'*       Call remote function module (RFC_READ_TABLE)
'*----------------------------------------------------------------------*
'*       --&amp;gt;oFunctionmodule RFC module object
'*       --&amp;gt;oFields         Table fields information
'*       &amp;lt;--oData           Read table data
'*----------------------------------------------------------------------*
Private Function callFunction(oFunctionmodule As Object, oFieldsTable As Object, oData As Collection) As Boolean

    'Set return value
    callFunction = False

' Data Definition ======================================================*
    Dim row         As Collection
    Dim oDataTable  As Object
    Dim oDataRow    As Object
    Dim oField      As Object

' Process ==============================================================*

    'Call function
    oFunctionmodule.Call
    If oFunctionmodule.Exception &amp;lt;&amp;gt; "" Then
        MsgBox ("Error of function module call:" &amp;amp; oFunctionmodule.Exception)
        Exit Function
    End If

    'Get export parameter "DATA"
    Set oDataTable = oFunctionmodule.Tables(C_RFCPARA_DATA)
    
    'In the case of the 1st call
    If oData.Count = 0 Then
    
        'Read data and Add to Collection object
        For Each oDataRow In oDataTable.Rows
            Set row = New Collection
        
            For Each oField In oFieldsTable.Rows
                row.Add Item:=Trim(Mid(oDataRow.Value(C_RFCPARA_COL_VALUE), CInt(oField.Value(C_RFCPARA_COL_OFFSET)) + 1, CInt(oField.Value(C_RFCPARA_COL_LENGTH)))), _
                        Key:=oField.Value(C_RFCPARA_COL_FIELDNAME)
            Next oField
            
            oData.Add Item:=row, Key:=CStr(oData.Count)
                        
        Next oDataRow
        
    Else
        'Read data and Update to Collection object
        For Each oDataRow In oDataTable.Rows
            Set row = oData.Item(CStr(oDataRow.Index - 1))
        
            For Each oField In oFieldsTable.Rows
                row.Add Item:=Trim(Mid(oDataRow.Value(C_RFCPARA_COL_VALUE), CInt(oField.Value(C_RFCPARA_COL_OFFSET)) + 1, CInt(oField.Value(C_RFCPARA_COL_LENGTH)))), _
                        Key:=oField.Value(C_RFCPARA_COL_FIELDNAME)
            Next oField

        Next oDataRow
    End If
    
' Terminate ===========================================================*
    oDataTable.FreeTable

    'Set return value
    callFunction = True

End Function

'*&amp;amp;---------------------------------------------------------------------*
'*&amp;amp;      appendData
'*&amp;amp;---------------------------------------------------------------------*
'*       Append data to MS-Access table
'*----------------------------------------------------------------------*
'*       --&amp;gt;oFields         Table fields information
'*       --&amp;gt;oData           Read table data
'*       --&amp;gt;sTableName      Read table name
'*----------------------------------------------------------------------*
Private Function appendData(oFields As Collection, oData As Collection, sTableName As String) As Boolean

    On Error GoTo eHandler
    
    'Set return value
    appendData = False

' Data Definition ======================================================*
    Dim db              As DAO.Database     'My Database
    Dim recordset       As DAO.recordset    'Read records set
    Dim row             As Collection
    Dim field           As Collection
    
' Process ==============================================================*
    'Create DB instance and table recordset
    Set db = CurrentDb()
    Set recordset = db.OpenRecordset(sTableName, dbOpenDynaset)

    For Each row In oData
        recordset.AddNew
            For Each field In oFields
                recordset.Fields(field.Item(C_RFCPARA_COL_FIELDNAME)) = row.Item(field.Item(C_RFCPARA_COL_FIELDNAME))
            Next field
        recordset.Update
    Next row
    
' Terminate ===========================================================*
    Set recordset = Nothing
    Set db = Nothing

    'Set return value
    appendData = True

    Exit Function

eHandler:
    'Not appear an error even when the type of a table column differs from the type of reading.
    If Err.Number = 3421 Then
        Resume Next
    Else
        MsgBox "System Error : " &amp;amp; Err.Number &amp;amp; " " &amp;amp; Err.Description
    End If

End Function
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Wed, 12 Dec 2007 08:03:21 GMT</pubDate>
    <dc:creator>Former Member</dc:creator>
    <dc:date>2007-12-12T08:03:21Z</dc:date>
    <item>
      <title>Download table data by Microsoft Access</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/download-table-data-by-microsoft-access/m-p/3197663#M762003</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I developed the script to which all records of the table were downloaded by the macro of Microsoft Access.&lt;/P&gt;&lt;P&gt;It builds it in according to the following procedures.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. Create Empty new access file.&lt;/P&gt;&lt;P&gt;2. Create new module.&lt;/P&gt;&lt;P&gt;3. Copy &amp;amp; Paste following VBA code.&lt;/P&gt;&lt;P&gt;4. Select "Tool" -&amp;gt; "Reference setting". Check on to "Microsoft ADO Ext. 2.8 for DDL and Security"&lt;/P&gt;&lt;P&gt;5. Save module.&lt;/P&gt;&lt;P&gt;6. Create new macro. Select "Execute procedure" and input procedure name "testConnect()".&lt;/P&gt;&lt;P&gt;7. Execute macro, and  follow the prompt and have FUN!!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;
'*----------------------------------------------------------------------*
'*  Program Name : SAP Table Data Downloader
'*  Created on : 2007/11/28      Author : Nobubyoshi Kikuchi(ABeam)
'*----------------------------------------------------------------------*
'*  Updated on : yyyy/mm/dd      Author :
'*  Request for change No :
'*  Remarks :
'*----------------------------------------------------------------------*

' Public Constant Definition ======================================================*
Public Const C_RFCNAME_READTABLE        As String = "RFC_READ_TABLE"
Public Const C_RFCPARA_FIELDS           As String = "FIELDS"
Public Const C_RFCPARA_DATA             As String = "DATA"
Public Const C_RFCPARA_COL_FIELDNAME    As String = "FIELDNAME"
Public Const C_RFCPARA_COL_OFFSET       As String = "OFFSET"
Public Const C_RFCPARA_COL_LENGTH       As String = "LENGTH"
Public Const C_RFCPARA_COL_TYPE         As String = "TYPE"
Public Const C_RFCPARA_COL_FIELDTEXT    As String = "FIELDTEXT"
Public Const C_RFCPARA_COL_VALUE        As String = "WA"
Public Const C_RFCPARA_QUERY_TABLE      As String = "QUERY_TABLE"
Public Const C_RFCPARA_DELIMITER        As String = "DELIMITER"
Public Const C_RFCPARA_NO_DATA          As String = "NO_DATA"
Public Const C_RFCPARA_ROWSKIPS         As String = "ROWSKIPS"
Public Const C_RFCPARA_ROWCOUNT         As String = "ROWCOUNT"
Public Const C_PROGRESS_MSG_01          As String = "Creating SAP Connection (1/5)"
Public Const C_PROGRESS_MSG_02          As String = "Getting table fields information (2/5)"
Public Const C_PROGRESS_MSG_03          As String = "Creating table at MS-Access (3/5)"
Public Const C_PROGRESS_MSG_04          As String = "Reading table data (4/5)"
Public Const C_PROGRESS_MSG_05          As String = "Appending data (5/5)"
Public Const C_PROGRESS_MSG_99          As String = " "
Public Const C_SAP_FUNCTION_CLASS       As String = "SAP.Functions"


'*&amp;amp;---------------------------------------------------------------------*
'*&amp;amp;      testConnect
'*&amp;amp;---------------------------------------------------------------------*
'*       This function
'*----------------------------------------------------------------------*
'*       &amp;lt;Non paramente&amp;gt;
'*----------------------------------------------------------------------*
Public Function testConnect()

    Dim sTableName As String
    
    sTableName = InputBox("Import table name")

    createReadTable (sTableName)

End Function

'*&amp;amp;---------------------------------------------------------------------*
'*&amp;amp;      createReadTable
'*&amp;amp;---------------------------------------------------------------------*
'*       1.Connect to SAP
'*       2.Get table fileds information
'*       3.Create table in MS-Access
'*       4.Read table data from SAP table
'*       5.Append data to MS-Access table
'*----------------------------------------------------------------------*
'*       --&amp;gt;sTableName      Read table name
'*----------------------------------------------------------------------*
Public Function createReadTable(sTableName As String)

   On Error GoTo eHandler

' Data Definition ======================================================*
    
    Dim oSAP            As Object           'SAP object
    Dim oConnection     As Object           'SAP Connection object
    Dim oFields         As Collection       'Table fields collection
    Dim oData           As Collection       'Table data collection

    Set oFields = New Collection
    Set oData = New Collection
    
' Process ==============================================================*

    'Check table name
    If sTableName = Empty Then
        MsgBox "Please input table name"
        Exit Function
    End If

    'Create SAP connection
    SysCmd acSysCmdSetStatus, C_PROGRESS_MSG_01
    If createConnection(oSAP, oConnection) = False Then
        Exit Function
    End If

    'Get table fields
    SysCmd acSysCmdSetStatus, C_PROGRESS_MSG_02
    If getTableFields(oSAP, oFields, sTableName) = False Then
        Exit Function
    End If

    'Create table at MS-Access
    SysCmd acSysCmdSetStatus, C_PROGRESS_MSG_03
    If createTable(oFields, sTableName) = False Then
        Exit Function
    End If

    'Read table data
    SysCmd acSysCmdSetStatus, C_PROGRESS_MSG_04
    If readTableData(oSAP, oFields, sTableName, oData) = False Then
        Exit Function
    End If

    'Append data
    SysCmd acSysCmdSetStatus, C_PROGRESS_MSG_05
    If appendData(oFields, oData, sTableName) = False Then
        Exit Function
    End If

    SysCmd acSysCmdSetStatus, C_PROGRESS_MSG_99
    
' Terminate ===========================================================*
    Set oFields = Nothing
    Set oData = Nothing
    Set oConnection = Nothing
    Set oSAP = Nothing
    
    Exit Function

eHandler:
    MsgBox "System Error : " &amp;amp; Err.Number &amp;amp; " " &amp;amp; Err.Description &amp;amp; "(" &amp;amp; Err.Source &amp;amp; ")"
    Exit Function
End Function

'*&amp;amp;---------------------------------------------------------------------*
'*&amp;amp;      createConnection
'*&amp;amp;---------------------------------------------------------------------*
'*       Connect to SAP (Not Silent Logon)
'*----------------------------------------------------------------------*
'*       &amp;lt;--oSAP            SAP object
'*       &amp;lt;--oConnection     Connection object
'*----------------------------------------------------------------------*
Private Function createConnection(oSAP As Object, oConnection As Object) As Boolean

    'Set return value
    createConnection = False

    'Create SAP instance
    Set oSAP = CreateObject(C_SAP_FUNCTION_CLASS)
    'Create SAP connection
    Set oConnection = oSAP.Connection

    'Logon information(Using silent logon)
    'oConnection.Applicationserver = "XXX.XXX.XXX.XXX"
    'oConnection.Client = "XXX"
    'oConnection.user = "XXXXXXXXX"
    'oConnection.language = "J"
    'oConnection.password = "XXXXXXX"
    
    'SAP logon (if you want silent logon, change FALSE to TRUE)
    If oConnection.logon(0, False) &amp;lt;&amp;gt; True Then
        MsgBox "Logon failure"
        Exit Function
    End If
    
    'Set return value
    createConnection = True
    
End Function

'*&amp;amp;---------------------------------------------------------------------*
'*&amp;amp;      getTableFields
'*&amp;amp;---------------------------------------------------------------------*
'*       Get table fields information
'*----------------------------------------------------------------------*
'*       --&amp;gt;oSAP            SAP object
'*       &amp;lt;--oFields         Table fields information
'*       --&amp;gt;sTableName      Read table name
'*----------------------------------------------------------------------*
Private Function getTableFields(oSAP As Object, oFields As Collection, sTableName As String) As Boolean

    'Set return value
    getTableFields = False

' Data Definition ======================================================*
    Dim oFunctionmodule As Object       'SAP Function module object
    Dim oTempFields     As Object       'Temporary object
    Dim row             As Object       'Table row object

' Process ==============================================================*
    'Create remote function module instance
    Set oFunctionmodule = oSAP.Add(C_RFCNAME_READTABLE)
    
    'Set function module parameters
    oFunctionmodule.exports(C_RFCPARA_QUERY_TABLE) = sTableName
    oFunctionmodule.exports(C_RFCPARA_DELIMITER) = ""
    oFunctionmodule.exports(C_RFCPARA_NO_DATA) = "X"
    oFunctionmodule.exports(C_RFCPARA_ROWSKIPS) = 0
    oFunctionmodule.exports(C_RFCPARA_ROWCOUNT) = 0
    
    'Call remote function modele
    oFunctionmodule.Call
    If oFunctionmodule.Exception &amp;lt;&amp;gt; "" Then
        MsgBox ("Error of function module call:" &amp;amp; oFunctionmodule.Exception)
        Exit Function
    End If
    
    'Get table fields information
    Set oTempFields = oFunctionmodule.Tables(C_RFCPARA_FIELDS)
    For Each row In oTempFields.Rows
        Set oField = New Collection
        oField.Add Item:=row.Value(C_RFCPARA_COL_FIELDNAME), Key:=C_RFCPARA_COL_FIELDNAME
        oField.Add Item:=row.Value(C_RFCPARA_COL_OFFSET), Key:=C_RFCPARA_COL_OFFSET
        oField.Add Item:=row.Value(C_RFCPARA_COL_LENGTH), Key:=C_RFCPARA_COL_LENGTH
        oField.Add Item:=row.Value(C_RFCPARA_COL_TYPE), Key:=C_RFCPARA_COL_TYPE
        oField.Add Item:=row.Value(C_RFCPARA_COL_FIELDTEXT), Key:=C_RFCPARA_COL_FIELDTEXT
        oFields.Add oField
    Next row

' Terminate ===========================================================*
    Set oTempFields = Nothing

    'Set return value
    getTableFields = True

End Function

'*&amp;amp;---------------------------------------------------------------------*
'*&amp;amp;      createTable
'*&amp;amp;---------------------------------------------------------------------*
'*       Create table in MS-Access
'*----------------------------------------------------------------------*
'*       --&amp;gt;oFields         Table fields information
'*       --&amp;gt;sTableName      Read table name
'*----------------------------------------------------------------------*
Private Function createTable(oFields As Collection, sTableName As String) As Boolean

    'Set return value
    createTable = False

' Data Definition ======================================================*
    Dim catalog         As ADOX.catalog     'Catalog object
    Dim table           As ADOX.table       'Table object
    Dim row             As Collection       'Table row object
    
' Process ==============================================================*
    'Create and Activetion current project instance
    Set catalog = New ADOX.catalog
    catalog.ActiveConnection = CurrentProject.Connection

    'Clear import table
    For Each table In catalog.Tables
        If sTableName = table.Name Then
            catalog.Tables.Delete sTableName
        End If
    Next table
    Set table = Nothing

    'Create table instance
    Set table = New ADOX.table
    table.Name = sTableName
    
    'Define table fileds
    For Each row In oFields
               
        'Append columns by types
        Select Case row.Item(C_RFCPARA_COL_TYPE)
            Case "C"    'Char
                table.Columns.Append row.Item(C_RFCPARA_COL_FIELDNAME), adVarWChar
            Case "D", "T"   'Date and Time
                table.Columns.Append row.Item(C_RFCPARA_COL_FIELDNAME), adVarWChar
            Case "P"    '
                table.Columns.Append row.Item(C_RFCPARA_COL_FIELDNAME), adDouble
            Case Else
                table.Columns.Append row.Item(C_RFCPARA_COL_FIELDNAME), adVarWChar
        End Select
        
        'Set nullable attribute
        table.Columns(row.Item(C_RFCPARA_COL_FIELDNAME)).Attributes = adColNullable
        
    Next row
    
    'Append table to catalog
    catalog.Tables.Append table
    
' Terminate ===========================================================*
    Set catalog = Nothing
    Set table = Nothing

    'Set return value
    createTable = True

End Function

'*&amp;amp;---------------------------------------------------------------------*
'*&amp;amp;      readTableData
'*&amp;amp;---------------------------------------------------------------------*
'*       Read SAP table data
'*----------------------------------------------------------------------*
'*       --&amp;gt;oSAP            SAP object
'*       --&amp;gt;oFields         Table fields information
'*       --&amp;gt;sTableName      Read table name
'*       &amp;lt;--oData           Read table data
'*----------------------------------------------------------------------*
Private Function readTableData(oSAP As Object, oFields As Collection, sTableName As String, oData As Collection) As Boolean

    'Set return value
    readTableData = False

' Data Definition ======================================================*
    Dim iLength         As Integer
    Dim row             As Collection   'Table row object
    Dim oFieldsTable    As Object
    Dim oFunctionmodule As Object       'SAP Function module object

    Set oFunctionmodule = Nothing

' Process ==============================================================*
    'Create remote function module instance
    Set oFunctionmodule = oSAP.Add(C_RFCNAME_READTABLE)
    
    'Set function module parameters
    oFunctionmodule.exports(C_RFCPARA_QUERY_TABLE) = sTableName
    oFunctionmodule.exports(C_RFCPARA_DELIMITER) = ""
    oFunctionmodule.exports(C_RFCPARA_NO_DATA) = ""     'I want data!!
    oFunctionmodule.exports(C_RFCPARA_ROWSKIPS) = 0
    oFunctionmodule.exports(C_RFCPARA_ROWCOUNT) = 0

    'Create FIELDS table parameter object
    Set oFieldsTable = oFunctionmodule.Tables(C_RFCPARA_FIELDS)
    
    'Initialize
    oFieldsTable.FreeTable
    iLength = 0
        
    'Set import parameter and Call function
    For Each row In oFields

        'Calls every 512 bytes (The limit of RFC_READ_TABLE)
        iLength = iLength + row.Item(C_RFCPARA_COL_LENGTH)
        If iLength &amp;lt;= 512 Then
        
            oFieldsTable.Rows.Add
            oFieldsTable(oFieldsTable.RowCount, C_RFCPARA_COL_FIELDNAME) = row.Item(C_RFCPARA_COL_FIELDNAME)
        
        Else
            'Call remote function module
            If callFunction(oFunctionmodule, oFieldsTable, oData) = False Then
                Exit Function
            End If
            oFieldsTable.FreeTable
            iLength = row.Item(C_RFCPARA_COL_LENGTH)
            oFieldsTable.Rows.Add
            oFieldsTable(oFieldsTable.RowCount, C_RFCPARA_COL_FIELDNAME) = row.Item(C_RFCPARA_COL_FIELDNAME)
        End If

    Next row

    'Call remote function module
    If callFunction(oFunctionmodule, oFieldsTable, oData) = False Then
        Exit Function
    End If
    
    'Set return value
    readTableData = True


End Function

'*&amp;amp;---------------------------------------------------------------------*
'*&amp;amp;      callFunction
'*&amp;amp;---------------------------------------------------------------------*
'*       Call remote function module (RFC_READ_TABLE)
'*----------------------------------------------------------------------*
'*       --&amp;gt;oFunctionmodule RFC module object
'*       --&amp;gt;oFields         Table fields information
'*       &amp;lt;--oData           Read table data
'*----------------------------------------------------------------------*
Private Function callFunction(oFunctionmodule As Object, oFieldsTable As Object, oData As Collection) As Boolean

    'Set return value
    callFunction = False

' Data Definition ======================================================*
    Dim row         As Collection
    Dim oDataTable  As Object
    Dim oDataRow    As Object
    Dim oField      As Object

' Process ==============================================================*

    'Call function
    oFunctionmodule.Call
    If oFunctionmodule.Exception &amp;lt;&amp;gt; "" Then
        MsgBox ("Error of function module call:" &amp;amp; oFunctionmodule.Exception)
        Exit Function
    End If

    'Get export parameter "DATA"
    Set oDataTable = oFunctionmodule.Tables(C_RFCPARA_DATA)
    
    'In the case of the 1st call
    If oData.Count = 0 Then
    
        'Read data and Add to Collection object
        For Each oDataRow In oDataTable.Rows
            Set row = New Collection
        
            For Each oField In oFieldsTable.Rows
                row.Add Item:=Trim(Mid(oDataRow.Value(C_RFCPARA_COL_VALUE), CInt(oField.Value(C_RFCPARA_COL_OFFSET)) + 1, CInt(oField.Value(C_RFCPARA_COL_LENGTH)))), _
                        Key:=oField.Value(C_RFCPARA_COL_FIELDNAME)
            Next oField
            
            oData.Add Item:=row, Key:=CStr(oData.Count)
                        
        Next oDataRow
        
    Else
        'Read data and Update to Collection object
        For Each oDataRow In oDataTable.Rows
            Set row = oData.Item(CStr(oDataRow.Index - 1))
        
            For Each oField In oFieldsTable.Rows
                row.Add Item:=Trim(Mid(oDataRow.Value(C_RFCPARA_COL_VALUE), CInt(oField.Value(C_RFCPARA_COL_OFFSET)) + 1, CInt(oField.Value(C_RFCPARA_COL_LENGTH)))), _
                        Key:=oField.Value(C_RFCPARA_COL_FIELDNAME)
            Next oField

        Next oDataRow
    End If
    
' Terminate ===========================================================*
    oDataTable.FreeTable

    'Set return value
    callFunction = True

End Function

'*&amp;amp;---------------------------------------------------------------------*
'*&amp;amp;      appendData
'*&amp;amp;---------------------------------------------------------------------*
'*       Append data to MS-Access table
'*----------------------------------------------------------------------*
'*       --&amp;gt;oFields         Table fields information
'*       --&amp;gt;oData           Read table data
'*       --&amp;gt;sTableName      Read table name
'*----------------------------------------------------------------------*
Private Function appendData(oFields As Collection, oData As Collection, sTableName As String) As Boolean

    On Error GoTo eHandler
    
    'Set return value
    appendData = False

' Data Definition ======================================================*
    Dim db              As DAO.Database     'My Database
    Dim recordset       As DAO.recordset    'Read records set
    Dim row             As Collection
    Dim field           As Collection
    
' Process ==============================================================*
    'Create DB instance and table recordset
    Set db = CurrentDb()
    Set recordset = db.OpenRecordset(sTableName, dbOpenDynaset)

    For Each row In oData
        recordset.AddNew
            For Each field In oFields
                recordset.Fields(field.Item(C_RFCPARA_COL_FIELDNAME)) = row.Item(field.Item(C_RFCPARA_COL_FIELDNAME))
            Next field
        recordset.Update
    Next row
    
' Terminate ===========================================================*
    Set recordset = Nothing
    Set db = Nothing

    'Set return value
    appendData = True

    Exit Function

eHandler:
    'Not appear an error even when the type of a table column differs from the type of reading.
    If Err.Number = 3421 Then
        Resume Next
    Else
        MsgBox "System Error : " &amp;amp; Err.Number &amp;amp; " " &amp;amp; Err.Description
    End If

End Function
&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 12 Dec 2007 08:03:21 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/download-table-data-by-microsoft-access/m-p/3197663#M762003</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2007-12-12T08:03:21Z</dc:date>
    </item>
    <item>
      <title>Re: Download table data by Microsoft Access</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/download-table-data-by-microsoft-access/m-p/3197664#M762004</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I haven't gotten Nobubyoshi's code to work yet, but I wanted to mention something to everyone who tries. For whatever reason when I paste the code into my module there are three sets of comparators missing from the code. I believe they are all '&amp;lt;&amp;gt;' (not equal to). They are easy to find. They are colored red in my code window.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for sharing. I am sure we will get this up and running soon.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ben &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edit:&lt;/P&gt;&lt;P&gt;They were removed from here too!&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Test:&lt;/P&gt;&lt;P&gt;Equal: =&lt;/P&gt;&lt;P&gt;Not Equal: &amp;lt;&amp;gt;&lt;/P&gt;&lt;P&gt;Greater Than: &amp;gt;&lt;/P&gt;&lt;P&gt;Less Than: &amp;lt;&lt;/P&gt;&lt;P&gt;Equal To or Less Than: &amp;lt;=&lt;/P&gt;&lt;P&gt;Equal To or Greater Than: &amp;gt;=&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Edited by: Ben Rhoads on Mar 7, 2008 2:40 PM&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 07 Mar 2008 12:31:03 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/download-table-data-by-microsoft-access/m-p/3197664#M762004</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-07T12:31:03Z</dc:date>
    </item>
    <item>
      <title>Re: Download table data by Microsoft Access</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/download-table-data-by-microsoft-access/m-p/3197665#M762005</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Thanks for sharing this code. We got it all working and even added in some table filtering options. This saved us a bunch of work.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Ben &lt;SPAN __jive_emoticon_name="happy"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 14 Mar 2008 11:43:58 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/download-table-data-by-microsoft-access/m-p/3197665#M762005</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2008-03-14T11:43:58Z</dc:date>
    </item>
    <item>
      <title>Re: Download table data by Microsoft Access</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/download-table-data-by-microsoft-access/m-p/3197666#M762006</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;I'm getting errror "Error of function module call:SYSTEM_FAILURE" when executing "If callFunction(oFunctionmodule, oFieldsTable, oData)" in function readTableData().&lt;/P&gt;&lt;P&gt;Connection is working also the script already pulled the column names for the table into Access but not the tabledata.&lt;/P&gt;&lt;P&gt;Any ideas?&lt;/P&gt;&lt;P&gt;Thanks&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Mar 2013 04:20:56 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/download-table-data-by-microsoft-access/m-p/3197666#M762006</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2013-03-01T04:20:56Z</dc:date>
    </item>
    <item>
      <title>Re: Download table data by Microsoft Access</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/download-table-data-by-microsoft-access/m-p/3197667#M762007</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;This is the information according to the dump caused:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Error:&amp;nbsp; CX_SY_ASSIGN_CAST_UNKNOWN_TYPE&lt;/P&gt;&lt;P&gt;The specified type Typ "agr_1251" is unknown.&lt;/P&gt;&lt;P&gt;&amp;nbsp; &lt;/P&gt;&lt;P&gt;code: ASSIGN WORK TO &amp;lt;WA&amp;gt; CASTING TYPE (QUERY_TABLE)&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Fri, 01 Mar 2013 04:57:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/download-table-data-by-microsoft-access/m-p/3197667#M762007</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2013-03-01T04:57:12Z</dc:date>
    </item>
    <item>
      <title>Re: Download table data by Microsoft Access</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/download-table-data-by-microsoft-access/m-p/3197668#M762008</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P class="_38 direction_ltr" style="font-size: 13px;"&gt;error found. Table name has to be case sensitive. Now it is working.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P class="_3hi"&gt;&lt;/P&gt;&lt;DIV class="_1yr" style="margin-left: 4px;"&gt;&lt;SPAN class="_2oy"&gt;&lt;/SPAN&gt;&lt;P&gt;&lt;/P&gt;&lt;P style="margin-top: 10px;"&gt;&lt;SPAN class="emoticon emoticon_smile" style="background-position: no-repeat no-repeat;"&gt;&lt;/SPAN&gt; &lt;SPAN class="emoticon emoticon_smile" style="background-position: no-repeat no-repeat;"&gt;&lt;/SPAN&gt; &lt;SPAN class="emoticon emoticon_smile" style="background-position: no-repeat no-repeat;"&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;/DIV&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Sat, 02 Mar 2013 19:00:30 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/download-table-data-by-microsoft-access/m-p/3197668#M762008</guid>
      <dc:creator>Former Member</dc:creator>
      <dc:date>2013-03-02T19:00:30Z</dc:date>
    </item>
  </channel>
</rss>

