HELP!!! The following code populates a combobox with the names of customers "cust_name".....What I need is...

I have a combobox called cbcustname2 it contains the customer names from a SQL database field called cust_name1....When I dropdown the combobox and click on a customer name then the fields in the form for are automatically filled with the correct fields such as phone number and email, etc....The problem that I have is the the combobox has a autocomplete class on it that like to erase the combbox and when this happens i get an exception telling me that I need a value...I'm noe sure 100% what the error says but I think that since there is nothing in the comboc that correspondes to what it want to display in the form then I get an error....how can I default values to a emty combobox that doesn't retrieve information from the database.   I think this might have been rambling a little so I apologize...   thanks


Private Sub PopulateForm2()
        Dim cnSQL As SqlConnection
        Dim cmSQL As SqlCommand
        Dim drSQL As SqlDataReader
        Dim strSQL As String
        Dim objListItem As ListItem
        Dim strID As String
        'Dim ctrl As Control

        Try
            'Get primary Key from Listbox
            objListItem = CType(cbcustname2.SelectedItem, ListItem)

            'Build Select statement to query customer information from the cust_id table
            strSQL = "SELECT MIN, " & _
                     "cust_name1, " & _
                     "cust_zip1, " & _
                     "cust_add1, " & _
                     "cust_add2, " & _
                     "cust_city1, " & _
                     "cust_phone1, " & _
                     "cust_fax1, " & _
                     "cust_email1, " & _
                     "cust_web1, " & _
                     "cust_bowname1, " & _
                     "cust_conname1, " & _
                     "cust_conadd1, " & _
                     "cust_conadd2, " & _
                     "cust_concity1, " & _
                     "cust_conzip1, " & _
                     "cust_conphone1, " & _
                     "cust_confax1, " & _
                     "cust_con_add_check, " & _
                     "sales_id, " & _
                     "bow_type_id, " & _
                     "cust_type_id, " & _
                     "info_state_id1, " & _
                     "info_state_id2 " & _
                     "FROM cust_id " & _
                     "WHERE MIN = " & objListItem.ID
            cnSQL = New SqlConnection(ConnectionString)
            cnSQL.Open()

            cmSQL = New SqlCommand(strSQL, cnSQL)
            drSQL = cmSQL.ExecuteReader()

         

            If drSQL.Read() Then
                'Populate form with the data
                txtMIN.Text = drSQL.Item("MIN").ToString()
                txtcust_name1.Text() = drSQL.Item("cust_name1").ToString()
                txtmarinazip1.Text() = drSQL.Item("cust_zip1").ToString()
                txtmarinaadd1.Text() = drSQL.Item("cust_add1").ToString()
                txtmarinaadd2.Text() = drSQL.Item("cust_add2").ToString()
                txtmarinacity1.Text() = drSQL.Item("cust_city1").ToString()
                txtmarinaphone1.Text() = drSQL.Item("cust_phone1").ToString()
                txtmarinafax1.Text() = drSQL.Item("cust_fax1").ToString()
                txtmarinaemail1.Text() = drSQL.Item("cust_email1").ToString()
                txtmarinaweb1.Text() = drSQL.Item("cust_web1").ToString()
                txtmarinabowname1.Text() = drSQL.Item("cust_bowname1").ToString()
                txtconname1.Text() = drSQL.Item("cust_conname1").ToString()
                txtconadd1.Text() = drSQL.Item("cust_conadd1").ToString()
                txtconadd2.Text() = drSQL.Item("cust_conadd2").ToString()
                txtconcity1.Text() = drSQL.Item("cust_concity1").ToString()
                txtconzip1.Text() = drSQL.Item("cust_conzip1").ToString()
                txtconphone1.Text() = drSQL.Item("cust_conphone1").ToString()
                txtconfax1.Text() = drSQL.Item("cust_confax1").ToString()
                conadddifmarina.Checked = CType(drSQL.Item("cust_con_add_check"), Boolean)
                strID = drSQL.Item("sales_id").ToString()
                FindItemByID(cbsalesman2, strID)

                strID = drSQL.Item("bow_type_id").ToString()
                FindItemByID(cbbowtype2, strID)

                strID = drSQL.Item("cust_type_id").ToString()
                FindItemByID(cbcustomertype2, strID)

                strID = drSQL.Item("info_state_id1").ToString()
                FindItemByID(cbmarinastate2, strID)

                strID = drSQL.Item("info_state_id2").ToString()
                FindItemByID(cbconstate2, strID)

            End If

            ' Close and Clean up objects
            drSQL.Close()
            cnSQL.Close()
            cmSQL.Dispose()
            cnSQL.Dispose()

        Catch e As SqlException
            MsgBox(e.Message, MsgBoxStyle.Critical, "SQL Error")

        Catch e As Exception
            MsgBox(e.Message, MsgBoxStyle.Critical, "General Error")
        End Try
    End Sub
brian_leightyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
You need to post the auto complete class for the combo box for that is where the problem most likely lies.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
amyhxuCommented:
I am not sure which autocompletecombo you are using, sounds like the one I provided.
If you are using mine, since I've used it so many times, I have the confidence that the behavior you described is unlikely to happen if you use it correctly. So can you show the code where you populate the autocompletecombo and wherever you interact with the autocompletecombo (any code that mentions that combo)?
brian_leightyAuthor Commented:
i found it....

the problem that is...... yes your code does work amyhxu but I needed to tweak one thing...ended up being similar to the question you already answered....

splitting this questions points

but will be asking another question..........please look for it.....
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.