Solved

Error 91 on Combobox event

Posted on 2008-10-17
8
185 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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
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 Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…

708 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

20 Experts available now in Live!

Get 1:1 Help Now