Solved

Error 91 on Combobox event

Posted on 2008-10-17
8
193 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
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…

831 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