Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't Unload Form

Status
Not open for further replies.

norason

Programmer
Jan 28, 2009
139
US
I'm trying to stop a form and go back the form that called it. The calling form is fmMain and the called form is fmStatus.

I'd like fmStatus to recognize when it is not visible and automatically return to fmMain. fmStatus has a comm communication where it constantly polls a comm port and updates the screen. I've tried putting this recognition in the comm logic to bail out, but it didn't work. I was hoping that clicking on the red X on the form would be sufficient to stop fmStatus.



For Each frm In Forms
If frm.Name = "fmStatus" Then
If frm.Visible = False Then
Unload fmStatus
Load fmMain
Exit Function
End If
End If
Next

If also added a 'CLOSE' button on fmStatus to try to bail out:


Private Sub CmdStatusClose_Click()
Do Until fmStatus.Visible = False
Unload fmStatus
fmStatus.Show = False
Loop

Load fmMain
End Sub

When I step thru the CLOSE button logic, it jumps out of the loop routine and goes to the Private Sub Form_Load() where the fmStatus.Show is called in the first place, so it doesn't shut down fmStatus.

Any help would be greatly appreciated.

Gary



 
That is because you reload fmMain each time, which opens fmStatus. One solution is to create a global boolean, and only show fmStatus if you set it to true (say on the first time fmMain opens); set it to false when & where appropriate.
Global vars can be a pain in larger apps though.

Illegitimi non carborundum.
 
Done unload frm.main when you show frmStatus, just do frmMain.visible=false
When the frm.Status is finished make frmMain visible again. This won't reload frm.Status
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top