Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1552
  • Last Modified:

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

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
Mike Eghtebas
Asked:
Mike Eghtebas
  • 5
  • 3
  • 2
  • +3
4 Solutions
 
avi247Commented:
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
 
Erick37Commented:
How do you open Form2?

What code is in Form_Load ?

What is in Comman_Click?
0
 
TheClickMasterCommented:
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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
abithCommented:
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
 
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
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
 
Erick37Commented:
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
 
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
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
 
Erick37Commented:
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
 
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
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
 
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
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
 
avi247Commented:
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
 
anvCommented:
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
 
Mike EghtebasDatabase and Application DeveloperAuthor Commented:
The problem was a connection to the backend database prematurally was being set to noting.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

The 14th Annual Expert Award Winners

The results are in! Meet the top members of our 2017 Expert Awards. Congratulations to all who qualified!

  • 5
  • 3
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now