Link to home
Start Free TrialLog in
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?
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
Try using the Shown event instead of Load event of form.
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()
I have also tried commenting out all of the code in the openemployer load event and i still get the error
> 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

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Accept http:#a35783706 as your solution (I didn't really contribute anything).
my answer was correct