Skip to Content
0
Former Member
Dec 13, 2011 at 05:01 AM

Combobox - Object reference not set to an instance of an object

187 Views

Hi Experts, please check my code.

In my ItemEvent.

When I try to changed the value of my Combobox then messagebox will show and display the current value of my combobox. But there's a error Object reference not set to an instance of an object.

Try
            Select Case pVal.Action_Success
                Case False

                Case True
                    Select Case pVal.EventType
                        Case SAPbouiCOM.BoEventTypes.et_FORM_LOAD

                            'If pVal.FormType = 2000060006 Then

                            Call AddItemCodeCombo()

                            'End If

                        Case SAPbouiCOM.BoEventTypes.et_CLICK
                            Select Case pVal.ItemUID
                                Case "cmdSave"

                            End Select
                        Case SAPbouiCOM.BoEventTypes.et_COMBO_SELECT And pVal.Before_Action = False
                            Select Case pVal.ItemUID
                                Case "cFrom"

                                    oItem = oForm.Items.Item("cFrom")
                                    Dim oCombo As SAPbouiCOM.ComboBox ' = oForm.Items.Item("cFrom")
                                    oCombo = oItem.Specific
                                    SBO_Application.MessageBox(oCombo.Selected.Value)


                            End Select
                    End Select
            End Select


        Catch ex As Exception

            MessageBox.Show(ex.Message)

        End Try

And this code is to fill my combobox.

Sub AddItemCodeCombo()

        Dim oCompany As SAPbobsCOM.Company = SBO_Application.Company.GetDICompany
        Dim RS As SAPbobsCOM.Recordset
        Dim oCombo As SAPbouiCOM.ComboBox = oForm.Items.Item("cFrom").Specific

       
        Try
           If oCombo.ValidValues.Count > 0 Then
                For i As Integer = 0 To oCombo.ValidValues.Count - 1
                    oCombo.ValidValues.Remove(0, SAPbouiCOM.BoSearchKey.psk_Index)
                Next
            End If

            RS = oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset)
            RS.DoQuery("SELECT dbName, cmpName FROM [SBO-COMMON].dbo.SRGC")
            'RS.MoveFirst()

            'If RS.RecordCount > 0 Then

            Do While Not RS.EoF

                oCombo.ValidValues.Add(RS.Fields.Item(0).Value.ToString, RS.Fields.Item(1).Value.ToString)
               
                RS.MoveNext()

            Loop

            'End If
            oCombo.Select(0, SAPbouiCOM.BoSearchKey.psk_Index)


        Catch ex As Exception

            MessageBox.Show(ex.Message)

        Finally

            RS = Nothing

        End Try

    End Sub