Skip to Content
author's profile photo
Former Member

-5002 error ("No Data ") when adding record to a UserTable

B1 2007A

Here's my code. I've stripped it about as far as I could to try and solve this problem... but I must be missing something. Basically, I referenced the UIDIBasicApp for the UserTables portion.

In the "PopulateUserTable" subroutine, where I attempt to add the record with:

lngRetCode = objUserTable.Add()

... lngRetCode comes back as "-5002". The error message is "No Data ".

I've added records with the same data into the table through B1 User-Defined Windows and it accepts the data without a problem. I've been re-checking the code, and searching the forums and the help file since last week, and I haven't found any reference to a problem like this.

Any ideas? Thanks!

Module Module1

    Public WithEvents objSboApp As SAPbouiCOM.Application
    Public WithEvents objSboCompanyDi As SAPbobsCOM.Company
'----------------------------------
    Public Sub Main()

        ConnectUI()
        ConnectDI()
        CreateUserTable("TP_WhereUsed")
        PopulateUserTable("TP_WhereUsed")

    End Sub
'----------------------------------
    Public Function ConnectUI()

        Dim objSboUiApi As SAPbouiCOM.SboGuiApi
        objSboUiApi = New SAPbouiCOM.SboGuiApi

        Dim sConnectionString As String
        sConnectionString = "0030002C0030002C00530041005000420044005F00440061007400650076002C0050004C006F006D0056004900490056"
        objSboUiApi.Connect(sConnectionString)

        objSboApp = objSboUiApi.GetApplication

    End Function
'----------------------------------
    Public Function ConnectDI()

        objSboCompanyDi = New SAPbobsCOM.Company

        Try
            objSboCompanyDi = objSboApp.Company.GetDICompany()
        Catch
            objSboApp.MessageBox(Err.Description)
            Exit Function
        End Try

    End Function
'----------------------------------
    Public Sub CreateUserTable(ByVal TableName As String)

        Dim lngRetCode As Long
        Dim lngErrCode As Long
        Dim strErrMsg As String

        Dim oUserTablesMD As SAPbobsCOM.UserTablesMD

        oUserTablesMD = objSboCompanyDi.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserTables)

        oUserTablesMD.TableName = TableName
        oUserTablesMD.TableDescription = TableName
        lngRetCode = oUserTablesMD.Add

        If lngRetCode <> 0 Then
            Select Case lngRetCode
                Case Is = -2035
                    'Table already exists.
                    Exit Sub
                Case Else
                    objSboCompanyDi.GetLastError(lngErrCode, strErrMsg)
                    objSboApp.MessageBox("Error - Table not created: " & strErrMsg)
            End Select

        Else
            objSboApp.SetStatusBarMessage("Table: " & oUserTablesMD.TableName & " was added successfully", SAPbouiCOM.BoMessageTime.bmt_Short, False)
        End If

    End Sub
'----------------------------------
    Private Sub PopulateUserTable(ByVal TableName As String)

        Dim lngRetCode As Long, lngErrCode As Long, strErrMsg As String
        Dim strCode As String, strName As String, intArrayCounter As Integer

        Dim objUserTable As SAPbobsCOM.UserTable
        objUserTable = objSboCompanyDi.UserTables.Item(TableName)

        intArrayCounter = 0
        Do Until intArrayCounter > 10

            strCode = "Code" & CStr(intArrayCounter)
            strName = "Name" & CStr(intArrayCounter)

            lngRetCode = objUserTable.Code = strCode
            lngRetCode = objUserTable.Name = strName
            lngRetCode = objUserTable.Add()
            intArrayCounter = intArrayCounter + 1

            objSboCompanyDi.GetLastError(lngErrCode, strErrMsg)

        Loop

    End Sub
'----------------------------------
End Module

Add comment
10|10000 characters needed characters exceeded

  • Follow
  • Get RSS Feed

1 Answer

  • Best Answer
    author's profile photo
    Former Member
    Posted on Aug 21, 2007 at 03:00 PM

    Hi

    Try your code with the lines I've added to the code of your CreateUserTable function. Hope it works!

        Public Sub CreateUserTable(ByVal TableName As String)
            Dim lngRetCode As Long
            Dim lngErrCode As Long
            Dim strErrMsg As String
     
            Dim oUserTablesMD As SAPbobsCOM.UserTablesMD 
            oUserTablesMD = objSboCompanyDi.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserTables)
     
            oUserTablesMD.TableName = TableName
            oUserTablesMD.TableDescription = TableName
            lngRetCode = oUserTablesMD.Add
     
            If lngRetCode <> 0 Then
                Select Case lngRetCode
                    Case Is = -2035
                        'Table already exists.
                        Exit Sub
                    Case Else
                        objSboCompanyDi.GetLastError(lngErrCode, strErrMsg)
                        objSboApp.MessageBox("Error - Table not created: " & strErrMsg)
                        System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserTablesMD)
                        oUserTablesMD = Nothing
                        GC.Collect() ' free occupied resource
                End Select
            Else
                objSboApp.SetStatusBarMessage("Table: " & oUserTablesMD.TableName & " was added successfully", SAPbouiCOM.BoMessageTime.bmt_Short, False)
    System.Runtime.InteropServices.Marshal.ReleaseComObject(oUserTablesMD)
                oUserTablesMD = Nothing
                GC.Collect() ' free occupied resource
            End If 
        End Sub
    
    
    

    Add comment
    10|10000 characters needed characters exceeded