Good day, I would ask for your help, my code below is giving me an error whether I open my new window(application/form?) resulting to appearance of the error "Object reference...." first before the said application. What is the problem in this codes? Thank you for your help. =)

    Private Sub searchacquisition_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles searchacquisition.TextChanged
        Try
            Connect()
            Dim SQL1 As String
            SQL1 = "Select * from newacquisition"
            FillData(SQL1)
            OleA.Fill(Dset, "newacquisition")
            Dim col2 As New AutoCompleteStringCollection
            Dim c As New Integer
            For c = 0 To Dset.Tables("newacquistion").Rows.Count - 1
                col2.Add(Dset.Tables("newacquisition").Rows(c)("title").ToString())

            Next

            searchacquisition.AutoCompleteSource = AutoCompleteSource.CustomSource
            searchacquisition.AutoCompleteCustomSource = col2
            searchacquisition.AutoCompleteMode = AutoCompleteMode.Suggest
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

`

It would help to know which line was referenced in the error.

If I'm not mistaken, generally that error is from not initializing an object when it is declared, then trying to give it a value. In your code SQL1, Dset, searchacquisition, OleA might fall in that category. SQL1 is simple, try this, Dim SQL1 As String = "Select * from newacquisition". It looks like searchacquisition is a textbox, so it should be OK. That leaves Dset and OleA to check in you're other code.

Hi!

The error you are receiving, appears when for example we do not initialize an object and try to access one of its property so in this case the the object does not exists so we can not access its property.

I have a couple of questions and few guidelines for you:

Questions:

1) Have you tried to step debug it?
2) Have you checked which line is the cause of this error ?

Guidelines:

1) Verify that, is 'OleA' variable initialized ?
2) In these lines:

FillData(SQL1)
OleA.Fill(Dset, "newacquisition")

what is your intentions here ? Is it a TWO times fill ? 'OleA.Fill' is already filling 'Dset' with data. Isn't it ?

3) Make sure this at this line :

col2.Add(Dset.Tables("newacquisition").Rows(c)("title").ToString())

we have a table inside which contains atleast one table with name "newacquisition" and a column in it with name "title".

4) Is search 'searchacquisition' variable initialized ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.