Forum Discussion
HKosova
Alumni
11 years agoFrom your code, it looks like UserForm1_OnShow is an event handler assigned to the form's Show event. Calling Show() inside this event handler creates an infinite recursion, which causes the crash.
There're two ways to show a form.
1) Modal mode - the script is paused until the user closed the form.
function sa()
{
var res = UserForms.UserForm1.ShowModal();
if (res == mrOK) {
Log.Message("Form was closed via OK button.");
}
else {
Log.Message("Form was closed via another button.");
}
}
For this to work, make sure to set the ModalResult property of the form buttons in the form designer. Example for the OK button:
2) Non-modal mode - the script execution continues after the form is displayed, and the script should explicitly close the form when it's no longer needed.
function sa()
{
UserForms.UserForm1.Show();
// Do something
// ...
UserForms.UserForm1.Hide();
}
Hope this helps!