• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2048
  • Last Modified:

VB6 - Runtime Error 364 - "Object was already unloaded"....

Hi Everyone,

I'm trying to debug a problem in one of my applications that I can't seem to duplicate in my development environment.  What's happening is that the user is switching between two open VB forms in the application (both are open on the desktop), but sporadically, if a user clicks a button on one form after using the other form, they get an error message saying "Run-Time Error 364: Object was already unloaded...".  

I am unable to give specifics, because the user is not giving me specifics.  

Strangely, if the user restarts her computer, and uses the application, they can switch between forms and use the application properly without any errors.

I am COMPLETELY stumped.  Please help!

Thanks,
Jason
0
jdhindsa
Asked:
jdhindsa
1 Solution
 
jpaulinoCommented:
Can you post the code where ?

You using load/unload to open/close the forms. Could you use .visible property instead ?
0
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
this can happen if in the form unload event, you try to use one of the form's properties.
at least that is what I had once...
0
 
jdhindsaAuthor Commented:
jpaulino/angellll:

The user is not exiting forms...so unload is not the cause of the problem (!?!?) ... instead they just have one form in the foreground and one in the background....

The series of events are as follows:

User opens a form called frmMTDetails.frm --> the user performs Shipping functions on this form.
The user then switches to frmTruckScanMain.frm (which is a different vb project - while still keeping frmMTDetails.frm open) --> performs error checking actions.  Clicks "Exit" on this form.

Private Sub cmdExit_Click()
    Unload Me
End Sub

...which calls:

Private Sub Form_Unload(Cancel As Integer)
  On Error Resume Next
  LogMsg "Destroying SoundManager..."
  Set MySounds = Nothing
  LogMsg "Destroying DatabaseManager..."
  MyDB.DisconnectDB
  Set MyDB = Nothing
  MyLogManager.StopLogging
  Set MyLogManager = Nothing
End Sub

Then the user switches back to frmMTDetails.frm --> tries to perform more shipping functions --> then the error message pops up.

 .... please help!
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
jpaulinoCommented:
Is it possible to have more then on open application ?
How do you call the second windows (frmTruckScanMain.frm) ?
0
 
Javin007Commented:
It is quite possible that for whatever reason, your various function calls here are taking too long, and Windows is getting ahead of itself with the unload process.  Then, as you're trying to call "MyLogManager.StopLogging" or somesuch, the VB6 automatic garbage collection has already beat you to it, shutting that down.  (Talking theory here.)

Your best way to check this would NOT be in the Form_Unload event, but rather in the Form_QueryUnload event, like so:

Private Sub Form_Unload(Cancel As Integer)
    If Not booObjectsSuccessfullyUnloaded Then Cancel = 1
End Sub

Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  On Error Resume Form_QueryUnload_Error
  LogMsg "Destroying SoundManager..."
  Set MySounds = Nothing
  LogMsg "Destroying DatabaseManager..."
  MyDB.DisconnectDB
  Set MyDB = Nothing
  MyLogManager.StopLogging
  Set MyLogManager = Nothing
  booObjectsSuccessfullyUnloaded = True
  Exit Sub
Form_QueryUnload_Error:
  LogMsg "Failed..."
  Resume Next
End Sub
0
 
jayneeIT ManagerCommented:
Also check that there isn't any code in the Form_Activate event that might be unloading the form unintentionally....
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now