Really wierd error.

nate

Freshman
Joined
Dec 2, 2006
Messages
36
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!
 
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:

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

Good luck :)
 
MrPaul,

this is my line:
Visual Basic:
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.
 
You mentioned cboContact in the fist post and cboContacts in the second post...could it be as simple as a typo?
 
Back
Top