vasant
asked on
UnLoading a form and loading it again!
I am trying to develop a bus scheduling software.
To generate a schedule user has to enter certain number of buses. But when the user enters buses less than the minimum required, what I am doing is giving an error message and unloading the output form. (Code for generating the schedule is in the Form_load event of the output form). The software then takes the user back to the Data entry form.
But when I try clicking the "run the schedule" command button again, it does not go to the Form_load event of the Output form at all. It just loads the output form with few controls. So I have to kind of go back and run the schedule again and it works then.
Does anyone have any idea as to why it is doing that?
Any suggestions would be greatly appreciated.
Thanks
Vasant
To generate a schedule user has to enter certain number of buses. But when the user enters buses less than the minimum required, what I am doing is giving an error message and unloading the output form. (Code for generating the schedule is in the Form_load event of the output form). The software then takes the user back to the Data entry form.
But when I try clicking the "run the schedule" command button again, it does not go to the Form_load event of the Output form at all. It just loads the output form with few controls. So I have to kind of go back and run the schedule again and it works then.
Does anyone have any idea as to why it is doing that?
Any suggestions would be greatly appreciated.
Thanks
Vasant
Form load occurs when the form is initially instantiated. This generally happens only once. Form_Activate fires every time the form is given focus.
You can do a UNLOAD to dump the form, but all memory associated with it will be freed and any vars will vanish. Put the code in your main procedure (just block copy out of the Form_Load event). then you can fire it at will with something like:
Formx.hide
call doprocess
Formx.show
M
You can do a UNLOAD to dump the form, but all memory associated with it will be freed and any vars will vanish. Put the code in your main procedure (just block copy out of the Form_Load event). then you can fire it at will with something like:
Formx.hide
call doprocess
Formx.show
M
ASKER
Well... Mark's suggestion was great... I actually figured that out. I did pretty much the same thing.
Thanks Mark.
Vasant
Thanks Mark.
Vasant
Good habits include preloading forms at the start of the program while splash screen is displayed. This means you dont want much code in the FORM LOAD events. Instead use Show and Hide to display the desired forms. To run code when a form is shown you would use the FORM ACTIVATE event and not the FORM LOAD event. Hope it helps. This technique is actually going to solve more problems than just the one you currently face. Happy programming!
Without seeing the code its not easy to imagine exactly what you are doing but one other thought is you want to use the REFRESH method on things that dont look correct. Requery, refresh and if your problem has to do with databases linked to controls I often like to use unbound controls for the users to work with rather than having them touching the bound controls directly because it will cause indexed fields to be updated and possible cause you to wind up with unwanted results and side affects..
ASKER
Thanks Rayford for your suggestion.
This is my first VB Project actually. I have learned a lot from the mistakes I have made. I should have written the code in Modules instead of just a big chunk of code. I guess that would have helped too.
Vasant
This is my first VB Project actually. I have learned a lot from the mistakes I have made. I should have written the code in Modules instead of just a big chunk of code. I guess that would have helped too.
Vasant
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks for your help Bhargava. I could figure out the problem.
If you liked my answer so much why did you give the points to Bhargawa? 8-(
M
M
ASKER
Well... I am kind of new to this Expert Exchange thing. Yours was a comment, right? So it didn't ask me as to what I want to do with the answer. It didnt' propose those 4 options (Excellent, good, etc.). Whereas Bhargava's suggestion was a proposed answer. Hence I could give points to him.
Tell me how to give points for a comment, I would do that right away.
Tell me how to give points for a comment, I would do that right away.
Generally what you do is reject the answer and then tell the commenter to repost as a question to award points.
M
M
You can use a hidden textbox or a variable to have the number in.