Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Good Day everyone.

This one has me completely stumped - I don't even know where to start looking for a solution.
I have a form with a ComboBox (to select from a list of suppliers).
If the user clicks on the ComboBox and then scrolls down to, and then clicks on desired supplier everything works well.

However, if the user clicks on the Combobox and then keys in, say Q to select a supplier called, say 'Quality Supplies' the program goes into the SelectedIndexChanged sub for the Combobox and executes until it hits a condition that displays a message (MsgBox). As soon as the MsgBox code line attempts to execute the SelectedIndexChanged sub restarts.

Why does this happen?

The sub is fairly long but I know someone is going to ask to see it so here it is :

VB
Private Sub cbo_Supplier_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cbo_Supplier.SelectedIndexChanged
        Dim x As Integer
        Dim NonSA As Boolean = False

        If cbo_Supplier.Text = " No Supplier" Then
            cbo_Contact.Enabled = False
            tsp_Supplier_Query.Enabled = False
            Exit Sub
        End If

        cbo_Description.Items.Clear()
        cbo_Contact.Items.Clear()

        cbo_Incoterm.Text = ""
        cbo_Inco_Named_Place.Text = ""
        cbo_Inco_Place.Text = ""

        tsp_Supplier_Query.Enabled = True
        cbo_Contact.Enabled = True
        cbo_Description.Enabled = True
        mxt_Qty.Enabled = True
        cbo_Unit.Enabled = True
        txt_Price.Enabled = True
        txt_Discount.Enabled = True
        txt_Note.Enabled = True
        tsp_Supplier_Add_Contacts.Enabled = True
        cbo_Incoterm.Enabled = True
        cbo_Inco_Named_Place.Enabled = True
        cbo_Inco_Place.Enabled = True

        Try
            cn.ConnectionString = "Provider=" & cp & " Data Source=" & GlobalVariables.DBPath & GlobalVariables.DBName & ";Jet OLEDB:Database Password=HvtDaBoDa;"
            cn.Open()     'Open the connection   opennoclose
        Catch
        End Try

        Ssql = "SELECT SP_Number, SP_Bee_Level, SP_SA_Company, SP_BEE_Cert_Path, SP_Currency FROM Supplier WHERE SP_Name = '" & cbo_Supplier.Text & "'"
        da = New OleDb.OleDbDataAdapter(Ssql, cn)
        da.Fill(ds, "Supplier")

        cn.Close()

        GlobalVariables.SupplierNo = ds.Tables("Supplier").Rows(0).Item(0).ToString()

        lbl_Bee_Level.Text = ds.Tables("Supplier").Rows(0).Item(1).ToString()

        SaCompany = ds.Tables("Supplier").Rows(0).Item(2)

        lbl_Bee_Level.ForeColor = Color.DarkBlue
        If SaCompany Then
            chk_No_Vat.Visible = True
            If lbl_Bee_Level.Text > 5 Then
                MsgBox("Caution : BEE Status greater than 5")
                lbl_Bee_Level.ForeColor = Color.Crimson
                BeeOverride()
                If Not BeeAuthd Then
                    NewPurchaseOrder("Save")
                    Exit Sub
                End If
            ElseIf lbl_Bee_Level.Text = 0 Then
                MsgBox("Warning : No BEE Status")
                lbl_Bee_Level.ForeColor = Color.Red
                BeeOverride()
                If Not BeeAuthd Then
                    NewPurchaseOrder("Save")
                    Exit Sub
                End If
            End If
        Else
            chk_No_Vat.Visible = False
        End If

        If SaCompany Then
            lbl_SubTotalName.Text = "Sub Total"
            lbl_VatName.Visible = True
            lbl_Vat.Visible = True
            lbl_TotalName.Visible = True
            Lbl_Order_Value.Visible = True
            lbl_Bee_Level.Visible = True
            lbl_Bee.Visible = True
            cbo_Currency.Text = "South African Rand"
            cbo_Currency.Enabled = False
            lbl_Currency.ForeColor = Color.Black
            lbl_Currency.Font = New Font(lbl_Currency.Font, FontStyle.Regular)
            tss_Status.Text = "---"
        Else
            lbl_SubTotalName.Text = "    Total"
            lbl_VatName.Visible = False
            lbl_Vat.Visible = False
            lbl_TotalName.Visible = False
            Lbl_Order_Value.Visible = False
            lbl_Bee_Level.Visible = False
            lbl_Bee.Visible = False
            Try
                cbo_Currency.Text = ds.Tables("Supplier").Rows(0).Item(4)
            Catch
                MsgBox("No default currency for foreign company - Notify Supplier administrator")
            End Try
            cbo_Currency.Enabled = True
            lbl_Currency.ForeColor = Color.DarkSlateBlue
            lbl_Currency.Font = New Font(lbl_Currency.Font, FontStyle.Bold)
            NonSA = True
            MsgBox("Non-South African Company - Check CURRENCY")  ' <--------PROBLEM HERE
            tss_Status.Text = "Non-South African Company - Check CURRENCY"
        End If

        If ds.Tables("Supplier").Rows(0).Item(3).ToString() <> "" Then    'Bee Certificate path
            tsp_Supplier_View_Bee_Cert.Enabled = True
            BeeCertPath = ds.Tables("Supplier").Rows(0).Item(3).ToString()
        Else
            tsp_Supplier_View_Bee_Cert.Enabled = False
        End If

        ds.Clear()

        Try
            cn.ConnectionString = "Provider=" & cp & " Data Source=" & GlobalVariables.DBPath & GlobalVariables.DBName & ";Jet OLEDB:Database Password=HvtDaBoDa;"
            cn.Open()     'Open the connection   opennoclose
        Catch
        End Try

        Ssql = "SELECT SC_Contact_Name FROM Supplier_Contacts WHERE SC_Supplier_No = " & GlobalVariables.SupplierNo & " ORDER BY SC_Contact_No"
        da = New OleDb.OleDbDataAdapter(Ssql, cn)
        da.Fill(ds, "SupplierC")

        cn.Close()

        Try
            For x = 0 To ds.Tables("SupplierC").Rows.Count - 1
                cbo_Contact.Items.Add(ds.Tables("SupplierC").Rows(x).Item(0).ToString())
            Next x
        Catch
            MsgBox("No contacts for selected supplier")
        End Try

        Me.cbo_Contact.Text = ds.Tables("SupplierC").Rows(0).Item(0).ToString()

        ds.Clear()

        Ssql = "SELECT Description FROM Components WHERE Supplier = " & GlobalVariables.SupplierNo
        da = New OleDb.OleDbDataAdapter(Ssql, cn)
        da.Fill(ds, "Components")

        For x = 0 To ds.Tables("Components").Rows.Count - 1
            cbo_Description.Items.Add(ds.Tables("Components").Rows(x).Item(0).ToString())
        Next x

        ds.Clear()

        Ssql = "SELECT * FROM Supplier_Inco WHERE SI_Supplier_No = " & GlobalVariables.SupplierNo
        da = New OleDb.OleDbDataAdapter(Ssql, cn)
        da.Fill(ds, "IncoTerms")

        NoOfIncoterms = ds.Tables("IncoTerms").Rows.Count

        ReDim Incoterms(ds.Tables("IncoTerms").Rows.Count - 1)
        ReDim IncoNamed(ds.Tables("IncoTerms").Rows.Count - 1)
        ReDim IncoPlace(ds.Tables("IncoTerms").Rows.Count - 1)

        cbo_Incoterm.Items.Clear()

        For x = 0 To ds.Tables("IncoTerms").Rows.Count - 1
            Incoterms(x) = ds.Tables("IncoTerms").Rows(x).Item(3).ToString()
            IncoNamed(x) = ds.Tables("IncoTerms").Rows(x).Item(4).ToString()
            IncoPlace(x) = ds.Tables("IncoTerms").Rows(x).Item(5).ToString()
            cbo_Incoterm.Items.Add(ds.Tables("IncoTerms").Rows(x).Item(3).ToString() & " - " & Microsoft.VisualBasic.Left(cbo_Supplier.Text, 6))
        Next x

        If ds.Tables("IncoTerms").Rows.Count > 0 Then
            cbo_Incoterm.Text = ds.Tables("IncoTerms").Rows(0).Item(3).ToString()
            cbo_Inco_Named_Place.Text = ds.Tables("IncoTerms").Rows(0).Item(4).ToString()
            cbo_Inco_Place.Text = ds.Tables("IncoTerms").Rows(0).Item(5).ToString()
        End If

        cbo_Incoterm.Items.Add("---------")

        If SaCompany Then
            cbo_Incoterm.Items.Add("EXW")
            cbo_Incoterm.Items.Add("FCA")
            cbo_Incoterm.Items.Add("CPT")
            cbo_Incoterm.Items.Add("CIP")
            cbo_Incoterm.Items.Add("DAP")
        Else
            cbo_Incoterm.Items.Add("EXW")
            cbo_Incoterm.Items.Add("FCA")
            cbo_Incoterm.Items.Add("FAS")
            cbo_Incoterm.Items.Add("FOB")
            cbo_Incoterm.Items.Add("CFR")
            cbo_Incoterm.Items.Add("CIF")
            cbo_Incoterm.Items.Add("CPT")
            cbo_Incoterm.Items.Add("CIP")
            cbo_Incoterm.Items.Add("DAP")
            cbo_Incoterm.Items.Add("DAT")
            cbo_Incoterm.Items.Add("DDP")
            ''cbo_Incoterm.Items.Add(" ")
        End If

        ds.Clear()

        cn.Close()   'Close the connection

    End Sub   'cbo_Supplier_SelectedIndexChanged
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900