Re: Program Stays In Memory
You didn't include the form in the zip file.
Are you calling "Unload"
You need to call unload on each form
Of course, you can also just call end
But I have learned that this can be bad.
Re: Program Stays In Memory
And, in the form.unload code include the
set form = nothing
substitute the name of your form for "form"
Re: Program Stays In Memory
Sorry, the new zip file has the form.
Re: Program Stays In Memory
You only incluided the .vbp file and not the frmSplash, FormMain.frm, & Module1.bas.
Do not ever use End at all.
Re: Program Stays In Memory
I guess I didn't see where you set either form = nothing.
Re: Program Stays In Memory
If there is no error then your xlApp only gets Set to Nothing. It wont get .Quit. You need to either .Close or .Quit all your Excel object variables and then after that destroy them by setting them equal to nothing.
Re: Program Stays In Memory
You haven't included the module, but I can see part of the problem - you are not closing Excel properly.
In form load you should change this:
VB Code:
.Workbooks.Open "SOME DIRECTORY\OP Concerto Forecast.xls"
.Worksheets("Selection").Activate
to this:
VB Code:
Dim xlWorkbook as Excel.Workbook
Set xlWorkbook = .Workbooks.Open "SOME DIRECTORY\OP Concerto Forecast.xls"
xlWorkbook.Worksheets("Selection").Activate
End With
With xlWorkbook.Worksheets("Selection")
Then, remove the ".Quit" from the end of the With, and change the section from Done: onwards to this:
VB Code:
Done:
FormSplash.Hide
Set FormSplash = Nothing
xlWorkbook.close SaveChanges := False
Set xlWorkbook = Nothing
xlApp.Quit
Set xlApp = Nothing
Screen.MousePointer = 0
Exit Sub
AdoError:
If Err.Number = 32755 Then
Resume Done
Else
MsgBox Err.Description, vbCritical, "Error #: " & Err.Number & Err.Source
Resume Done
End If
Re: Program Stays In Memory
I've created over 50 other vbprojects and never set my startup form to nothing and none of those reside in memory. Any other ideas. I'll try and set both forms to nothing in the startup form unload event.
Re: Program Stays In Memory
The form object is not the problem. Excel remains running because just setting it to nothing will not quit the app and destroy it. Do you have any other excel object variables in the Module1.bas?
Re: Program Stays In Memory
Moved from Classic VB forum. :)
Re: Program Stays In Memory
Quote:
Originally Posted by RobDog888
The form object is not the problem. Excel remains running because just setting it to nothing will not quit the app and destroy it. Do you have any other excel object variables in the Module1.bas?
I do quit xlApp and then set it to nothing. I also have a chart object which I also set to nothing.
Re: Program Stays In Memory
Esham,
Your problem:
VB Code:
Done:
Unload FormSplash
' FormSplash.Hide
Set FormSplash = Nothing
You hide the form but never unload it. Call a routine at the end of you program like such: (Place this in a module and call it from your forms Unload event.
VB Code:
Public Sub UnloadAll()
Dim frm As Form
Dim ctl As Control
On Error Resume Next
For Each frm In Forms
For Each ctl In Controls
Set ctl = Nothing
Next
Unload frm
Set frm = Nothing
Next
End Sub
Re: Program Stays In Memory
I have a feeling that the code in the module (which isn't in the zip file) could be the cause of your program not closing.
The changes I suggested above should correct the issue with Excel.
Re: Program Stays In Memory
The module1.bas should be in the zip file. I 've updated it. Check again. Sorry about that.
Re: Program Stays In Memory
You should make similar changes to the CreateChart sub as I mentioned above.
Also, you should not have object variables declared as "New" anything when they are public (and arguably not at all). You should add a line like this instead when you want the application to open (in form_load and CreateChart):
Code:
Set xlApp = New Excel.Application
And Randem is correct about your splash form, you should be using the amended code as in his first example (or the other if you prefer).
Re: Program Stays In Memory
VB Code:
Public Sub UnloadAll()
Dim frm As Form
Dim ctl As Control
On Error Resume Next
For Each frm In Forms
For Each ctl In [COLOR=DarkRed]Controls[/COLOR]
Set ctl = Nothing
Next
Unload frm
Set frm = Nothing
Next
End Sub
[/QUOTE]
It gives me an error when I compile saying the variable is not defined.
Re: Program Stays In Memory
I also noticed that in your formmain's unload event your calling itself to unload again in that procedure creating a circular reference.
VB Code:
Private Sub Form_Unload(Cancel As Integer)
Unload FormSplash
'Unload FormMain 'Circular ref.
Set FormSplash = Nothing
Set FormMain = Nothing
End Sub
Also, switch the event to the Form_QueryUnload event instead. In case your clicking the 'x' at the top right corner to close the app. it will be sure to close and destroy all objects.
Re: Program Stays In Memory
Esham,
You did not state where you attempted to place the code or anything. The code does work I use it exactly as posted all the time. Did you place this code in a module?
Re: Program Stays In Memory
Quote:
Originally Posted by randem
Esham,
You did not state where you attempted to place the code or anything. The code does work I use it exactly as posted all the time. Did you place this code in a module?
Randem,
I placed your exact code into the Module1.bas and called it from FormMain.QueryUnload. What am I doing wrong?
VB Code:
Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
Call UnloadAll
End Sub
Re: Program Stays In Memory
Everything seems to be working now except for the Controls unload loop. Thanks for all the help!
randem,
Any suggestions on why that's not working. The Forms unload works fine, just not the Controls.
Re: Program Stays In Memory
It looks like a minor change is needed:
VB Code:
For Each ctl In [b]Frm.[/b]Controls