Skip to Content
author's profile photo Former Member
Former Member

Object variable or With block variable not set

Hi,

Purpose:

I am fetching data from ORDR (Sales Order) in a matrix where SO Status is Open & Users have to input their remarks why it is still pending.

Problem:

I am getting error "Object variable or With block variable not set" on my Private Sub PopulateMatrix()

The Code :

Private Sub PopulateMatrix()

oForm.Freeze(True)

Try

oMatrix = oForm.Items.Item("matx").Specific

oedit1 = oForm.Items.Item("6").Specific

oedit2 = oForm.Items.Item("8").Specific

Dim fromdate As String = oedit1.Value

Dim todate As String = oedit2.Value

oDS = oForm.DataSources.DBDataSources.Add("ordr")

strSQL = "Select DocNum, DocDate ,DocDueDate, CardName, DocTotal From ORDR where DocStatus ='O' "

oApplication.Utilities.ExecuteSQL(RS, strSQL)

oMatrix.FlushToDataSource()

For i = 1 To RS.RecordCount

oDS.SetValue("Col_Draft", i - 1, RS.Fields.Item("docnum").Value)

oDS.SetValue("Col_BPName", i - 1, RS.Fields.Item("CardName").Value)

oDS.SetValue("Col_DocDt", i - 1, RS.Fields.Item("DocDate").Value)

oDS.SetValue("Col_DueDt", i - 1, RS.Fields.Item("docDuedate").Value)

oDS.SetValue("Col_Total", i - 1, RS.Fields.Item("DocTotal").Value)

If i < RS.RecordCount Then

oDS.InsertRecord(i - 1)

End If

RS.MoveNext()

Next

If RS.RecordCount = 0 Then

oApplication.Utilities.Message("No Records Found", SAPbouiCOM.BoStatusBarMessageType.smt_Error)

Exit Try

End If

oMatrix.LoadFromDataSource()

oMatrix.AutoResizeColumns()

Catch ex As Exception

oApplication.Utilities.Message(ex.Message, SAPbouiCOM.BoStatusBarMessageType.smt_Error)

Finally

oForm.Freeze(False)

RS = Nothing

oDS = Nothing

strSQL = ""

End Try

End Sub

Thank you all in advance

John

Add a comment
10|10000 characters needed characters exceeded

Related questions

2 Answers

  • author's profile photo Former Member
    Former Member
    Posted on Sep 22, 2011 at 12:26 PM

    Hi John,

    This error means that you are trying to access any object that was not initialized.

    What seems from your code snippet is that you are trying to populate User Defined Form's matrix with the data from Sales Order (Open SOs).

    But

    oDS = oForm.DataSources.DBDataSources.Add("ordr") seems to be incorrect ;

    firstly here if oForm is the user defined form then you are trying to add ORDR as datasource table which is not possible.

    Instead you should have used the following line

    oDS = oForm.DataSources.DBDataSources.item("@UDT")

    Where @UDT is the name of user defined table to which the matrix will be bound.Also note that if this datasource is already added to the form , you should use item collection.

    So the right way is to add a dbdatasource referring to a user defined table and bound the matrix columns with the same database columns.

    Otherwise use UserDefined DataSource to bind the matrix columns.

    Hopefully this oDS object is not getting initialized and is the cause of the error.

    Regards,

    Pooja Singh.

    Add a comment
    10|10000 characters needed characters exceeded

  • author's profile photo Former Member
    Former Member
    Posted on Sep 23, 2011 at 05:35 AM

    Hi Pooja,

    Thanks for your reply, it was helpful.Though i found it was the ""oDS.SetValue("Col_Draft", i - 1, RS.Fields.Item("docnum").Value)""

    Which was giving problem, after modifying it i am getting the desired results.

    Thanks

    John

    Add a comment
    10|10000 characters needed characters exceeded

Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.