Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Object reference not set to an instance of an object.

 

I have a control on my form called cbocontact.

I call cbocontact.selecteditem.text and I get this wierd error. I have other cbo's that I use on this for the same exact way and get no errors. It is wierd. If I change the name I get the usually code corrections. Then I change the name back to it's original and the code errors or underlines are still there like the object doesnt exist. I tried deleting it and recreating it but It still causes the same error. Has anyone ever had this? Please Help!

Ignorance begins with I.
Posted

No item selected

 

It may not be that the cboContact itself is a null reference, but that the SelectedItem property is a null reference (no item selected). This is the default value for the control until an item has been selected. You should check that an item is selected first:

 

If (cboContact.SelectedItem IsNot Nothing) Then
   'Do something with cboContact.SelectedItem
End If

 

Good luck :)

Never trouble another for what you can do for yourself.
Posted

MrPaul,

 

this is my line:

If cboContacts.SelectedItem.Text > "" Then Recordset.Fields.Item("contact").Value = cboContacts.SelectedItem.Text

 

yet if I select something I don't get an error. What is weird is I have another combo box that I run the same code for and don't select anything either but it goes through fine. I must be missing something. I use this all the time.

Ignorance begins with I.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...