Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Run time error '364' - Object was unloaded

Posted on 2000-02-24
6
6,047 Views
Last Modified: 2010-07-27
I have an application that first displays a splash screen.  It then checks the system registry to see if the proper keys can be located.  If they are not located, the user is notified that the registry keys are being added by a message box.  When the user clicks 'OK' the app should then unload so that the next time the app is started the registry keys are there.  Everything works fine until I try to unload the app.  That is when I get the run time error 364.  Why am I getting this error?

Here is my code from my frmMain Load event:


StatusMsg "Loading application..."
  Show
  frmSplash.Show
  DoEvents
 
  Screen.MousePointer = vbDefault

  'Retrieve database path name from system registry
  gstrDatabasePath = GetSetting("Bankruptcy", "FilePaths", "Database", _
    "No Path")

  'Check returned database path name from system registry
  'If it equals 'No Path' then add settings to the registry
  If gstrDatabasePath = "No Path" Then
    Unload frmSplash
    MsgBox "The Bankruptcy Trustee Reporting application was not able to locate the proper entries in the System Registry for the application to function properly." _
      & Chr$(13) & Chr$(13) & "Click 'OK' to allow the application to make the proper entries into the System Registry.", _
      vbCritical, "Initial System Registry Entries Needed"
    SaveSetting "Bankruptcy", "FilePaths", "Database", "C:\Bankruptcy\Bankruptcy.mdb"
    SaveSetting "Bankruptcy", "FilePaths", "Data", "C:\Bankruptcy\Brupfile.fil"
    SaveSetting "Bankruptcy", "FilePaths", "Report", "C:\Bankruptcy\Bruplist.fil"
    SaveSetting "Bankruptcy", "FilePaths", "ExpFmt1", "A:\Rconfile.txt"
    SaveSetting "Bankruptcy", "FilePaths", "ExpFmt2", "A:\Rconfile.txt"
    SaveSetting "Bankruptcy", "FilePaths", "ExpFmt3", "A:\Arpfile.txt"
    SaveSetting "Bankruptcy", "FilePaths", "ExpFmt4", "A:\Recon.txt,A:\Stmt.txt,A:\Trancode.txt"
    SaveSetting "Bankruptcy", "FilePaths", "CrystalReports", "C:\Bankruptcy"
    MsgBox "The proper Registry entries have been made.  Please close and restart the application.", vbInformation, "Registry Update Successful"
    Unload Me
  Else
    'Test database connection
    gcnn.Open "Provider=Microsoft.Jet.OLEDB.3.51;Data Source =" & gstrDatabasePath
    'retrieve Tran Date from BkrpList
    rst.Open "BkrpList", gcnn
    gstrProcessDate = rst("Tran Date")
    rst.Close
    gcnn.Close
    Unload frmSplash
    StatusMsg "Ready"
  End If

Here is the code from my frmSplash:


Private Sub Form_GotFocus()
    Dim intPauseTime As Long
    Dim intStart As Long

    intPauseTime = 2
    intStart = Timer
    Do While Timer < intStart + intPauseTime
      DoEvents
    Loop

    frmMain.Show
End Sub

Private Sub Form_Load()
    Screen.MousePointer = vbHourglass
    lblVersion.Caption = "Version " & App.Major & "." & App.Minor & "." & App.Revision
    lblProductName.Caption = "Bankruptcy Trustee Reporting"
End Sub

Private Sub Form_Unload(Cancel As Integer)
  Set frmSplash = Nothing
End Sub


When I choose 'Debug' when I receive this error, it points to the following line of code in the frmSplash GotFocus event "frmMain.Show".

Any ideas you can give me will be greatly appreciated.  Also, any tips you can give to my coding in general would be a great help as I am new to VB.
0
Comment
Question by:jasonboetcher
6 Comments
 
LVL 20

Expert Comment

by:hes
ID: 2555736
Try using this instead in a module:

Public fMainForm As frmMain


Sub Main()
    frmSplash.Show
    frmSplash.Refresh
    Set fMainForm = New frmMain
    Load fMainForm
    Unload frmSplash


    fMainForm.Show
End Sub

And have the startup object as Sub Main
0
 
LVL 10

Accepted Solution

by:
caraf_g earned 25 total points
ID: 2555743
Add a .bas module to your project and code a Sub Main. Set your project properties - Startup Object is Sub Main.

StatusMsg "Loading application..."
  frmSplash.Show
  DoEvents
   
  Screen.MousePointer = vbDefault

  'Retrieve database path name from system registry
  gstrDatabasePath = GetSetting("Bankruptcy", "FilePaths", "Database", _
    "No Path")

  'Check returned database path name from system registry
  'If it equals 'No Path' then add settings to the registry
  If gstrDatabasePath = "No Path" Then
    MsgBox "The Bankruptcy Trustee Reporting application was not able to locate the proper entries in the System Registry for the application to function properly." _
      & Chr$(13) & Chr$(13) & "Click 'OK' to allow the application to make the proper entries into the System Registry.", _
      vbCritical, "Initial System Registry Entries Needed"
    SaveSetting "Bankruptcy", "FilePaths", "Database", "C:\Bankruptcy\Bankruptcy.mdb"
    SaveSetting "Bankruptcy", "FilePaths", "Data", "C:\Bankruptcy\Brupfile.fil"
    SaveSetting "Bankruptcy", "FilePaths", "Report", "C:\Bankruptcy\Bruplist.fil"
    SaveSetting "Bankruptcy", "FilePaths", "ExpFmt1", "A:\Rconfile.txt"
    SaveSetting "Bankruptcy", "FilePaths", "ExpFmt2", "A:\Rconfile.txt"
    SaveSetting "Bankruptcy", "FilePaths", "ExpFmt3", "A:\Arpfile.txt"
    SaveSetting "Bankruptcy", "FilePaths", "ExpFmt4", "A:\Recon.txt,A:\Stmt.txt,A:\Trancode.txt"
    SaveSetting "Bankruptcy", "FilePaths", "CrystalReports", "C:\Bankruptcy"
    MsgBox "The proper Registry entries have been made.", vbInformation, "Registry Update Successful"
  End If

'You don't need to close and restart!
 
    'Test database connection
    gcnn.Open "Provider=Microsoft.Jet.OLEDB.3.51;Data Source =" & gstrDatabasePath
    'retrieve Tran Date from BkrpList
    rst.Open "BkrpList", gcnn
    gstrProcessDate = rst("Tran Date")
    rst.Close
    gcnn.Close
    StatusMsg "Ready"

    Unload frmSplash

    frmMain.Show


frmSplash can be simplified:
Private Sub Form_Load()
    Screen.MousePointer = vbHourglass
    lblVersion.Caption = "Version " & App.Major & "." & App.Minor & "." & App.Revision
    lblProductName.Caption = "Bankruptcy Trustee Reporting"
End Sub

Is all you need
0
 

Author Comment

by:jasonboetcher
ID: 2555840
That worked great.  The only thing I had to add was another GetSetting command before I tested the connection to pick up the new registry key.  Thanks!
0
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

 
LVL 10

Expert Comment

by:caraf_g
ID: 2557061
Tip: avoid coding too much in event procedures, especially Load, Unload and Resize procedures. You also get into trouble coding stuff in _Change and _Click procedures for data-containing controls such as text boxes, combo boxes and so on.

This leads to what I call "tortuous event coding". You'll find that you have to start making exceptions for what triggered the event, because events could happen in a different order depending on whether the user clicked on a control, tabbed into it, the contents was changed by the user typing something or by the program itself... and so on. Makes for nasty spaghetti code...

Often you can achieve the same by approaching the code slightly differently.

In this case you put code in Form_GotFocus and Form_Load procedures. Instead, I took the code out and put them in a Sub Main, stabilising the product.
0
 
LVL 10

Expert Comment

by:caraf_g
ID: 2557062
BTW: Thanks for the points! ;-)
0
 

Expert Comment

by:email_rajeevshah
ID: 25662265
I am getting error :
Runtime error 364 object was unloaded

I have coded Form_Load event and on certain condition I want to UnLoad the current form and setfocus on MDI form's control.
What is the solution for this? or What is alternative for this?

Frontend :Visual Basic 6 EE
Backend : SQL Server

Private Sub Form_Load()
On Error GoTo errHandler: 'Added by Vishwas on 26/10/2009
  Dim rsUnlockRes As New ADODB.Recordset
  Dim STRSQL As String
  'Marked by Vishwas on 26/10/2009''SYS_RESOURCE prob
  STRSQL = "select * from sys_resource_in_process where user_name = '" & sUserName & "'  order by resource_name"
  'Added By Ashwani on 20/08/2006
  If rsUnlockRes.State = adStateOpen Then rsUnlockRes.Close
  rsUnlockRes.Open STRSQL, cn, adOpenForwardOnly, adLockReadOnly
  If Not (rsUnlockRes.EOF Or rsUnlockRes.BOF) Then
      lstUnlockRes.Clear
      rsUnlockRes.MoveFirst
      While Not (rsUnlockRes.EOF Or rsUnlockRes.BOF)
         lstUnlockRes.AddItem (rsUnlockRes.Fields("resource_name").Value)
         rsUnlockRes.MoveNext
      Wend
  End If
  If lstUnlockRes.ListCount = 0 Then
     MsgBox "No Resources are locked.", vbCritical
     'Unload Me 'Marked by Vishwas on 26/10/2009###Here error is
     Unload frmUnlockRes 'Marked by vishwas on 26/10/2009###Here error 
     frmAppMain.ucmnuMenu1.SetFocus 'Commented by Vishwas on 26/10/2009
     Exit Sub###Here errore is
'     'cmdUnlock.Enabled = False
''     cmdExit.SetFocus
  End If
  Exit Sub
errHandler:
If Err.Number <> 0 Then MsgBox "Error : " & CStr(Err.Number) & " : " & Err.Description, vbCritical, Me.Caption
End Sub

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
MS Access Search and Replace Using VBA 6 80
VBA: Select SQL query based on a config Sheet v2 11 49
VB6 - Convert HH:MM into Decimal 8 62
Advice in Xamarin 21 96
Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…

856 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