Avatar of ict-torquilclark
ict-torquilclark

asked on 

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

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?
Visual Basic.NET

Avatar of undefined
Last Comment
ict-torquilclark
Avatar of Hawkvalley1
Hawkvalley1
Flag of United States of America image

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
...
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Try using the Shown event instead of Load event of form.
Avatar of Todd Gerbert
Todd Gerbert
Flag of United States of America image

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)?
Avatar of ict-torquilclark
ict-torquilclark

ASKER

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()
Avatar of ict-torquilclark

ASKER

I have also tried commenting out all of the code in the openemployer load event and i still get the error
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

> 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.
ASKER CERTIFIED SOLUTION
Avatar of ict-torquilclark
ict-torquilclark

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Todd Gerbert
Todd Gerbert
Flag of United States of America image

Accept http:#a35783706 as your solution (I didn't really contribute anything).
Avatar of ict-torquilclark

ASKER

my answer was correct
Visual Basic.NET
Visual Basic.NET

Visual Basic .NET (VB.NET) is an object-oriented programming language implemented on the .NET framework, but also supported on other platforms such as Mono and Silverlight. Microsoft launched VB.NET as the successor to the Visual Basic language. Though it is similar in syntax to Visual Basic pre-2002, it is not the same technology,

96K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo