An error occurred creating the form. See Exception.InnerException for details.  The error is: Operation is not allowed when the object is open.

ict-torquilclark
ict-torquilclark used Ask the Experts™
on
I have been working on a v.net app for the last couple of days

i am now getting the following error when trying to interact with one of my forms

in this case all i am trying to do is use form1.show in a button click even and i get the error in the title

it has been working all day, what have i dont o break it?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Do you have any variables trying to access control properties when they are being declared?
These controls are not built yet as would cause an inner exception.
Example:

Public Class Form1
 Private wd As Integer = panel1.Width
...
Most Valuable Expert 2012
Top Expert 2014

Commented:
Try using the Shown event instead of Load event of form.
Todd GerbertIT Consultant
Top Expert 2010

Commented:
A quick Google of that exception message suggests it's primarily database-related. What code do you have in the button's Click event handler, in the Form's Sub New(), and in any of the Form's startup events (e.g. Load, Activate, Shown)?
Microsoft Azure 2017

Azure has a changed a lot since it was originally introduce by adding new services and features. Do you know everything you need to about Azure? This course will teach you about the Azure App Service, monitoring and application insights, DevOps, and Team Services.

Author

Commented:
this is the code on the button click event

'Gets EmployerRef and Passes to EmployerForm

        Dim rs As New ADODB.Recordset
        Dim sqlStr As String

        rs.CursorLocation = ADODB.CursorLocationEnum.adUseClient
        sqlStr = "SELECT EmployerRef FROM Employers WHERE FullName = '" & listboxEmployers.Text & "'"
        rs.Open(sqlStr, sqlCnn, ADODB.CursorTypeEnum.adOpenStatic, ADODB.LockTypeEnum.adLockOptimistic)

        OpenEmployer.Text = listboxEmployers.Text
        OpenEmployer.labelEmployerName.Text = listboxEmployers.Text
        OpenEmployer.Tag = rs.Fields("EmployerRef").Value
        OpenEmployer.Show()
        rs.Close()
        Me.Close()

Author

Commented:
I have also tried commenting out all of the code in the openemployer load event and i still get the error
Most Valuable Expert 2012
Top Expert 2014

Commented:
> OpenEmployer.labelEmployerName.Text = listboxEmployers.T
The above seems to be the offending line. You are accessing a label on form before its created. Comment that line out and see how it goes.
i figured out what it was

i went through and commented out all of the code on the openemployers form and it ran fine

i then went through and uncommennted a sub at a time until i found the offending procedure.

it turned out i was attempting to open a recordset that was already open.

who should get the points?

tqebert?
Todd GerbertIT Consultant
Top Expert 2010

Commented:
Accept http:#a35783706 as your solution (I didn't really contribute anything).

Author

Commented:
my answer was correct

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial