Solved

Error 91 on Combobox event

Posted on 2008-10-17
8
199 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
Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

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…
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.
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
Course of the Month5 days, 14 hours left to enroll

627 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