Skip to Content

"object reference not set to an instance of an object" error when tryin to post JE

Hi guys,

I keep getting this error "object reference not set to an instance of an object" when i run my code below. Can anyone help me out.

Public Class Form1
Dim oCompany As SAPbobsCOM.Company
Dim oJournal As SAPbobsCOM.JournalEntries
Dim oOrderDoc As SAPbobsCOM.Documents
Dim oBP As SAPbobsCOM.BusinessPartners
Dim OrdCodeString As String
Dim InvCodeString As String
Dim lRetCode, lErrCode As Long
Dim sErrMsg As String

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
Try

oCompany = New SAPbobsCOM.Company
oCompany.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2012
oCompany.Server = "DESKTOP-7T8DIME"
oCompany.CompanyDB = "DB_Woolly_Furniture"
oCompany.DbUserName = "sa"
oCompany.DbPassword = "Password123"
oCompany.UserName = "manager"
oCompany.Password = "manager"
If oCompany.Connect = 0 Then
MsgBox("Connected")
Else
MsgBox(oCompany.GetLastErrorDescription)
End If
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
Try
oJournal = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oJournalEntries)
oJournal.DueDate = Now
oJournal.TaxDate = Now
oJournal.Memo = "MY SDK Journal"

oJournal.Lines.AccountCode = "_SYS00000000018"
oJournal.Lines.Credit = 250
oJournal.Lines.LineMemo = "My line memo"
oJournal.Lines.Add()

oJournal.Lines.AccountCode = "_SYS00000000287"
oJournal.Lines.Debit = 250
oJournal.Lines.Add()


lRetCode = oJournal.Add()
If lRetCode <> 0 Then
oCompany.GetLastError(lErrCode, sErrMsg)
MsgBox("Error: " & lErrCode & ": " & sErrMsg)
Else
oCompany.GetNewObjectCode(OrdCodeString)
MsgBox("Added Journal no : " & OrdCodeString)
End If
Catch ex As Exception
MsgBox("Exception: " & ex.Message)
End Try
End Sub
End Class

Regards

Tichaona

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

1 Answer

  • May 11, 2017 at 08:36 AM

    Hi,

    Can you please make sure that you are connected to the company successfully?

    Also please note that each object has been instantiated correctly which you are refering in your code.

    Otherwise, tell us the line on which you are getting the error.

    Kind regards,

    ANKIT CHAUHAN

    SAP SME Support

    Add comment
    10|10000 characters needed characters exceeded