Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Error 91 on Combobox event

Posted on 2008-10-17
8
Medium Priority
?
202 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
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
 
LVL 6

Accepted Solution

by:
mirzas earned 1500 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
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…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses

721 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