0

I have a form which has a search feature - a single text field and command button; when the text field is filled-in a database query is executed and the result (if one result returned) is shown on the form via dynamic control fields.

When the search feature is used for the first time, the fields are created and the data is returned from the database, however when the search feature is re-ran I am getting the error "Object Reference not set to an instance of an object", the error occurs at:

initSearch(txtSearchInput.Text)

I am guessing that I am not handling the textfield properly for this type of use, can anyone please advise how else I should be doing this?

The txtSearchInput is not a dynamic field, it has been created through the design mode, the same for the command button. The above code is located in the command button On Click event:

 Private Sub btnGo_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnGo.Click
        Try
            initSearch(txtSearchInput.Text)
        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical, "Error Encountered")
        End Try


    End Sub

Any help would be greatly appreciated.

Thanks,

Matt

1
  • Found the problem, after doing a debug on the initSearch I found that at some point I was setting the txtField to nothing. I think I was attempting at clearing the searched for text (ie clearing the search box). Removed the nothing assignment and the error has gone away. Thanks to all for your help. Commented Oct 31, 2010 at 10:39

2 Answers 2

3

Any help would be greatly appreciated.

The error is not in the code you posted. The Text property of a TextBox, and the reference to a Form Textbox don't become null all of a sudden.

You probably have to debug into initSearch

Sign up to request clarification or add additional context in comments.

Comments

0

Did you test in the debugger if txtSearchInput is null?

Exception could be bubbling up from initSearch function, best way is to debug your code.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.