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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vbModal form within vbModal form? 1

Status
Not open for further replies.

JFoushee

Programmer
Joined
Oct 23, 2000
Messages
200
Location
US
Hello again.

I think I found my core problem to an earlier post...
(
I have Main Form A which calls vbModal Form B.
In the event Form B cannot do its job, the error handling prompts the user for additional information on vbModal Form C (Retry, Continue, Abort), and clears the Error object.

When a user clicks on a decision on Form C, I need Form C to go away, partially because on "Retry," it could come back again.
I have attempted
Code:
FormC.Hide: Set FormC = Nothing
from Form C, and also from Form B.

The introduction of Form C leaves the program in a suspended state upon assumed completion. This code..
Code:
Private Sub Form_Unload(Cancel As Integer)
  Dim myForm As Form
  For Each myForm In Forms
    Debug.Print myform.Name & vbTab & myForm.Visible
  Next
End Sub

reports that Form C is still out there and not visible. I click the Stop button to complete out the program.

Futhermore, clicking Retry on Form C (with no remedy pre-completed) causes the code to stop debugging at the line that, two seconds ago, bubbled-up an error and presented Form C.

Have other programmers worked with vbModal inside vbModal?
 
Ok, here's the test I did:

3 forms, Form1, Form2, Form3. On Form1, a command button that shows Form2 modally. On Form2, a command button that shows Form3 modally. On Form3, a command button that unloads Form3.
Also, on form1, another command button with the following code:
Code:
Dim frm As Form
For Each frm In Forms
    Debug.Print frm.Name & " " & frm.Visible
Next
Now, this all works as expected. I can never see anything but Form1 when I execute that code. Also, your code works as expected: FormC.Hide doesn't unload the form, it just hides it. If you want to unload it, say Unload FormC.

HTH

Bob
 
I'll accept that answer. Thanks!
 
You're most welcome. Incidentally, what
Code:
Set FormC = Nothing
accomplishes is simply to remove the reference relationship between FormC and the Form it references. It does nothing to the actual form object.

VB maintains a Forms collection which consists of all currently loaded forms. Forms are loaded by 1) being the startup form 2)calling their Show method, if not already loaded and 3)using the Load statement. In all three cases the form is added to the forms collection. On the other hand, the only thing that removes a form from the forms collection is unloading it. In code, that means using the Unload statement.

Playing around with Form variables has no effect on the forms collection.
Code:
dim frm as Form
Set frm = New Form2
does NOT add Form2 to the forms collection. Nor does setting a form variable to nothing remove a form that it references from same. You could do that with form variables, but would have to use the methods I gave in the previous paragraph, like so:
Code:
dim frm as Form
Set frm = New Form2
frm.Show   'would add an instance of Form2 to the Forms collection
unload frm 'would remove it

HTH

Bob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top