cancel
Showing results for 
Search instead for 
Did you mean: 

Problem in document number auto generation

Former Member
0 Kudos

Dear All,

I have created a screen in this screen,i want to generate a auto generate number

for that i have write a code but when am executing the program in VS2005,the form was loaded in SAPB1 2005,But am not getting the auto generate number in the particular coloumn.

It shows an error like pbject reference not set to an instance of an object

the code is,

Private Sub DCNumber()

Try

oForm = SBO_Application.Forms.Item("FormEditor")

Dim oRs As SAPbobsCOM.Recordset

oRs = ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)

oRs.DoQuery("Select DocNum IS NULL THEN '1' ELSE DocNum+1 from @SCDC")

Dim Auto As String = oRs.Fields.Item(0).Value

oForm.Freeze(True)

oForm.Items.Item("25").Specific.Value = Auto

oForm.Freeze(False)

Catch ex As Exception

SBO_Application.StatusBar.SetText(ex.Message)

End Try

End Sub

I call this function in,

Public Sub New()

MyBase.New()

SetApplication()

' Load the Tab Order form

LoadFromXML("SCDC.srf")

oForm = SBO_Application.Forms.Item("FormEditor")

oForm.Visible = True

DCNumber()

End Sub

Accepted Solutions (0)

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi,

oRs.DoQuery("select MAX( DocNum)+1 from @SCDC")

Dim Auto As String = oRs.Fields.Item(0).Value

if Auto ="0"or Auto ="" then

Auto =1

end if

let me know the result.

Regards,

Aslam

Former Member
0 Kudos

You could use Aslam's answer but then in one row and use it in a formatted search..


select ISNULL(MAX(DocNum),0) +1 from @SCDC

I think the error is in this line:


Dim oRs As SAPbobsCOM.Recordset
oRs = ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)

Should be:


Dim oRs As SAPbobsCOM.Recordset
oRs = (SAPbobsCOM.Recordset) ocompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)

Or in:


Dim Auto As String = oRs.Fields.Item(0).Value

Dim Auto As String = oRs.Fields.Item(0).Value.ToString()

But you can set a breakpoint and debug your code, then it's possible to see where is trown the error..

HTH

Regards Teun

Edited by: Teun Aben on Apr 15, 2009 10:42 PM

edy_simon
Active Contributor
0 Kudos

Hi Guru,

In which line does the VS threw the error "Object Refference not set to an instance of an object ?

looking at your code maybe you should change to


dim oEdit as sapbouicom.edittext
oedit = oForm.Items.Item("25").Specific
oedit.string = Auto

Former Member
0 Kudos

the sql query isnt correct, try it as

Select case when DocNum IS NULL THEN '1' ELSE DocNum+1 end  from dbo.[@SCDC]

Former Member
0 Kudos

Still it shows an error "object reference not set to an instance of an object"

Regards,

Guru

Former Member
0 Kudos

Try this one for the query:

Select IsNull(DocNum,0)+1 from dbo.[@SCDC\]

Thanks,

Gordon

Former Member
0 Kudos

Still it shows the same error

Regards,

Guru