-
April 17th, 2018, 10:16 PM
#1
Help with Modal Form unloading
I have a small VB6 executable that uses two forms. Form1 is the startup object and is used to submit data into a database. Form2 is used to view data from the database. There are times where data may need to be altered while viewing. In those situations, Form1 is shown as Modal and the fields are populated where they can be edited and saved, etc.
While writing this post, I believe I solved my issue which was wacky form behavior. The program was not terminating properly or would prematurely exit. I have a vague idea why setting Set Form1 = Nothing is necesssary after using Form1.Show vbModal and before using Form1.Show again, but if someone has a decent explanation I would be interested to hear it. Thanks.
Form1:
Code:
Private Sub Form_Load()
Debug.Print "Form1_Load Event Fired"
End Sub
Private Sub Command1_Click()
Form1.Hide
Form2.Show
End Sub
Private Sub Form_Unload(Cancel As Integer)
Debug.Print "Form1_Unload Event Fired"
End Sub
Form2:
Code:
Private Sub Form_Load()
Debug.Print "Form2_Load Event Fired"
End Sub
Private Sub Command1_Click()
Form1.Command1.Enabled = False
Form1.Show vbModal
End Sub
Private Sub Form_Unload(Cancel As Integer)
Debug.Print "Form2_Unload Event Fired"
Set Form1 = Nothing
Form1.Show
Form1.Command1.Enabled = True
End Sub
-
April 18th, 2018, 06:25 AM
#2
Re: Help with Modal Form unloading
You do not need to set it to nothing
The code you have does not unload the form when you click the button. It is just hiding it.
Try unloading form one after calling form2.show
Always use [code][/code] tags when posting code.
-
April 18th, 2018, 02:00 PM
#3
Re: Help with Modal Form unloading
Thanks for your reply.
Originally Posted by DataMiser
The code you have does not unload the form when you click the button. It is just hiding it.
The unload event fires when clicking the close(x). Form1 should hide when Form2 is opened. Form1 should show Modal when a command button is clicked on Form2. Form2 should unload and Form1 should show when the Form2 close(x) button is clicked. The program should terminate when Form1 is the only form loaded and the close(x) button is clicked.
Try unloading form one after calling form2.show
I did try your suggestion, but it didn't work. The problem seems to be because Form1 is shown again, but as Modal under Form2. Form2 becomes the owning form. When Form2 is closed, it also unloads Form1 and terminates the program instead of showing Form1 again.
You do not need to set it to nothing
It's the only thing that seems to work. If Form1.Modal = False was a valid attribute, that would make sense. Setting the Form equal to nothing resets some attribute related to Modality.
-
April 19th, 2018, 08:37 AM
#4
Re: Help with Modal Form unloading
I tried your code and it seems to work fine.
The only real issue I see is that if you show form1 then form2 then form1 and close form 2 it is not reloading form 1 from some reason and setting form1 to nothing seems to prevent this. Watching the code if the nothing is not there then it executes the form1 load then the form1 unload right after. Not sure why it would do this.
Last edited by DataMiser; April 19th, 2018 at 08:44 AM.
Always use [code][/code] tags when posting code.
-
April 25th, 2018, 05:22 PM
#5
Re: Help with Modal Form unloading
You're seeing exactly what I was seeing and also couldn't understand why. If vbModal is omitted from the show statement, then a nothing statement isn't necessary and all works fine too. ..but I have the need to use show modal from form2. The behavior is caused the modal statement, but I don't fully understand why or if "nothing" is the correct way to reset it. Thanks for taking the time to look at it. Appreciated.
-
April 26th, 2018, 07:34 AM
#6
Re: Help with Modal Form unloading
You might want to try moving the code to show form 1 from the unload event to the query unload event
Always use [code][/code] tags when posting code.
-
June 6th, 2018, 03:27 AM
#7
Re: Help with Modal Form unloading
I did just that, but I'm not using a form to collect the info, I'm simply collecting the info via a set of globals. Actually, I don't see how using another hidden form to collect the data would work. If you're working with a modal form, then you can't be working with another form until you dismiss it. And if you dismiss it, it can't very well be reporting values to another form, right? group d rrb admit card
-
July 18th, 2018, 07:10 AM
#8
Re: Help with Modal Form unloading
If you see any discrepancy in the Online Printed RRB Group D Result, you should contact the concerned authority before the exam schedules. If you fail to rectify the errors, you might not be allowed to sit in the Group & ALP examination or may face problems in further stages of the alp recruitment.
RRB ALP Admit Card RRB Group D Admit Card RRB Group D Result RRB ALP Result
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|