Solved

Operation is not allowed when the object is closed...vb6

Posted on 2004-09-23
13
1,524 Views
Last Modified: 2007-11-27
From Form1, via command1, I am opening Form2 (this works ok).  Although it is not necessary to click on command1 again,  because Form2 is already open, I get above error message when I do so.  And, to get rid of it one has to use Ctrl+Alt+Del keys to exit the vb application.

I tired to put break lines on command1_Click and Form_Active to see what lines causing the error.  I haven't been able to determine it.  Do you have any idea what this error exactly means and how I can handle it?

Thanks.
0
Comment
Question by:Mike Eghtebas
  • 5
  • 3
  • 2
  • +3
13 Comments
 
LVL 4

Expert Comment

by:avi247
ID: 12137539
1. What line throws this error? i.e. whats in your Command1_click method.
2. Is there anything you are doing when you open Form2, i.e. on Form2_load are any database or operations being done?
3. Is there any object in scope of Form1\Command1  and you are referencing in Form2
0
 
LVL 32

Expert Comment

by:Erick37
ID: 12137558
How do you open Form2?

What code is in Form_Load ?

What is in Comman_Click?
0
 
LVL 5

Assisted Solution

by:TheClickMaster
TheClickMaster earned 100 total points
ID: 12137672
How do you open form2?

You could try to disable the control until form 2 closed.

Put this into Command1_Click():
-
Command1.Enabled = false
-

Put this into Form_Unload() in form2:
-
Form1.Command1.Enabled = true
-

You could also open Form2 as modal:
In Command1_click() write:
-
Form2.Show vbModal, Me
-

0
 
LVL 5

Assisted Solution

by:abith
abith earned 100 total points
ID: 12137820
hi
before loading the form unload the form

ex:

unload form2
load form2
form2.show

else when yo click the command1 event disable the command button.

i think this will solve.  or it will be useful if you give the source code event

Abith
0
 
LVL 33

Author Comment

by:Mike Eghtebas
ID: 12138334
avi247,

Re:>1. What line throws this error?
"I haven't been able to determine it." see the question for more.

Re:> i.e. whats in your Command1_click method.
Form2.Show '<-- first time works but the second time around gives error

Re:>2. Is there anything you are doing when you open Form2, i.e. on Form2_load are any database or operations being done?
I have some code to put the Form1 on top and move around on got focus (I removed them, the same difference).

Re:>3. Is there any object in scope of Form1\Command1  and you are referencing in Form2
No.
---------------------------------
Erick37, Please see above response to avi247.
----------------------------------
TheClickMaster, I am clicking on a lable, no button to enable it.
---------------------------------
abith, I tried it didn't work.
---------------------------------
To all:

I am new to VB, I need the proper code to open a form and close to get back to the original form.  In my case, the original form stays visible, the second form opens and attaches to the original form.

Regards,

Mike
0
 
LVL 32

Accepted Solution

by:
Erick37 earned 200 total points
ID: 12138654
Step through the code, line by line to see what line is erroring out.

In Form_Load of form2, put a breakpoint in the first line of executable code.

Run the program.

When the program stops at the breakpoint, step through the code line by line (using the F8 key) taking note where any errors take place.

References:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon98/html/vbconusingbreakmode.asp
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon98/html/vbconrunningselectedportionsofyourapplication.asp
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 33

Author Comment

by:Mike Eghtebas
ID: 12138695
Erick37,

When I put break point, it doesn't produce error.  This becuase when if goes to code window, it also sets focus to the form (or form's code window).  This is why I tried to put break in Form_GotFocus and Form_Active events.  I have tried everything I know but I wasn't able to find the line which produces error.

I will take a look at your links now.

Thanks,

Mike
0
 
LVL 32

Expert Comment

by:Erick37
ID: 12138806
I'm sorry, I don't follow you.  Were you able to step through the code (F8)?  

And just to be clear - you are not connected to or referencing any database?
0
 
LVL 33

Author Comment

by:Mike Eghtebas
ID: 12138925
Erick37,

I have a routine to store some info in the backend.mdb (in Form_Deactivate).  rs.Colse is the line the error occurs.  I have to make sure rs (public variable) is not set to Nothing, I guess.  brb
0
 
LVL 33

Author Comment

by:Mike Eghtebas
ID: 12138980
I guess we have nailed it.  By mistake, I was setting my variables to nothing in Form_Deactivate.  I moved them to Query_Unload.  I will do some more tests with it and let you know about it.

Mike
0
 
LVL 4

Assisted Solution

by:avi247
avi247 earned 100 total points
ID: 12140048
Mike, a good idea would be to put On Error Resume Next  before rs.Close. Its a safe thing.

'your database code here
On Error Resume next
rs.Close
Set rs = nothing
set conn = nothing
0
 
LVL 10

Expert Comment

by:anv
ID: 12140159
hi eghtebas

make it a habit to use following code..

if rs.state = adOpen then rs.close
if rs.state = adclosed the rs.open...

me  too had this problem some time back,, since them i've statred using this b4 i open or close an object.. i check its state..first..

:))
0
 
LVL 33

Author Comment

by:Mike Eghtebas
ID: 12376830
The problem was a connection to the backend database prematurally was being set to noting.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

919 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now