Solved

Error 91 on Combobox event

Posted on 2008-10-17
8
189 Views
Last Modified: 2013-12-26
My forms visibility is set to invisible when the user requires the form he clicks on the
notifyicon which resizes the form and sets the data source for a combo box on the form resize
 event. The datasource is set with:

dt = New DataTable
                    SQL = "Select * from logon where companyid=" & CustID
                    data_adapter = New SqlDataAdapter(SQL, _
                    conString)

                    Dim DS As New DataSet
                    data_adapter.Fill(DS, "logon")
                    dt = DS.Tables(0)
                    If dt.Rows.Count > 0 Then
                        ComboBox2.DataSource = dt
                        ComboBox2.DisplayMember = dt.Columns(1).ToString
                        ComboBox2.ValueMember = dt.Columns(0).ToString
                        data_adapter.Dispose()
                    Else
                        ComboBox2.DataSource = Nothing
                    End If

When the combobox binds it fires the comboboxs selected index change event which throws an error 91 object reference not set to an instance of an object. This looks as though it is due to the form not being fully open when the event fires. If I set the datasource using a button on the form all works as expected. Is their any method to overcome this and allow the datasource to be set on the form resize event?

Regards,
JoeBo
0
Comment
Question by:JoeBo747
  • 4
  • 4
8 Comments
 
LVL 6

Expert Comment

by:mirzas
ID: 22739348
Put your code inside "VisibleChanged" event.

and execute your block only if the form is visible.

Let's see what happens.
0
 
LVL 1

Author Comment

by:JoeBo747
ID: 22739418
Hi miras,

Thanks for your suggestion, but I get the same error.

Regards,
joeBo
0
 
LVL 6

Expert Comment

by:mirzas
ID: 22739441
At which line does the debugger stop ?



Put a breakpoint at this line

If dt.Rows.Count > 0 Then
                        ComboBox2.DataSource = dt     <<--------


Verify that Combobox2 is not null/nothing
0
 
LVL 1

Author Comment

by:JoeBo747
ID: 22739578
Hi mirzas,

When the cursor gets to;

ComboBox2.DataSource = dt     <<--------

The SelectedIndexChanged event fires, the code in the event is;

            If Not Me.ComboBox2.Text = "" Then Me.EmailAdd.Text = Me.ComboBox2.SelectedItem(4).ToString

The error occurs here. If I place a breakpoint on the line and drill down into Me.ComboBox2.SelectedItem(4).ToString the row array exisits and contains the required value at index 4!

Regards,
JoeBo
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 6

Accepted Solution

by:
mirzas earned 500 total points
ID: 22739589
What about Me.EmailAdd.Text?

0
 
LVL 1

Author Comment

by:JoeBo747
ID: 22739708
Hi mirzas,

Yes thats where the error lies, if I add the line in the event:

Me.EmailAdd.Text = Nothing

In the SelectedIndexChanged event I get the same error!  Why?
Any Idea?

Regards,
JoeBo
0
 
LVL 1

Author Comment

by:JoeBo747
ID: 22740918
Hi mirzas,

Thanks for your assistance, I have found the issue, which was related to the emailadd textbox but was not related to any of the events! I had set it to emailadd = nothing when I should have set its value to emailadd.text = nothing!!! Doh.
Anyway I would have not found this so quickly witout your help. The points are yours.

Thank you,
JoeBo
0
 
LVL 6

Expert Comment

by:mirzas
ID: 22740948
Thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

943 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now