M
Microsoft
Word 2000
I have a user form that needs to run a couple of lines of code each time
it gets closed. I have the following in the click-event of my Close
button:
Private Sub cmdClose_Click()
Close FileNumber
Unload ufErrorLookup
End Sub
The problem is that this code does not run if the user clicks the "x" in
the upper-right corner of the form. Clicking the "x" probably unloads
the user form, so I'm not really concerned about that, but I am concerned
about running the Close FileNumber statement to close an open random
access file. The file needs to stay open until the user form is closed.
I know that it's possible to write Initialize event macros that will run
after a form has been loaded, but before it's displayed, so I figured
that it must also be possible to write a Close event macro that would run
every time the user form is closed--no matter how it gets closed.
However, I've been unable to find anything in Help on how to do this.
Currently, the only way I can think of to make sure the Close FileNumber
command runs is to add the following routine to my project:
Sub LoadUserForm()
ufErrorLookup.Show
Close FileNumber
End Sub
This would display the user form, and close the file after the user form
has been closed. I guess that's not a bad way to do it, but I think that
closing the file through the Close event of a form (if such a thing
exists) would be cleaner.
Is there a Close event for user forms? If so, what is the first line (I
tried "Private Sub UserForm_Close()" and "Private Sub UserForm_Exit()")?
--Tom
I have a user form that needs to run a couple of lines of code each time
it gets closed. I have the following in the click-event of my Close
button:
Private Sub cmdClose_Click()
Close FileNumber
Unload ufErrorLookup
End Sub
The problem is that this code does not run if the user clicks the "x" in
the upper-right corner of the form. Clicking the "x" probably unloads
the user form, so I'm not really concerned about that, but I am concerned
about running the Close FileNumber statement to close an open random
access file. The file needs to stay open until the user form is closed.
I know that it's possible to write Initialize event macros that will run
after a form has been loaded, but before it's displayed, so I figured
that it must also be possible to write a Close event macro that would run
every time the user form is closed--no matter how it gets closed.
However, I've been unable to find anything in Help on how to do this.
Currently, the only way I can think of to make sure the Close FileNumber
command runs is to add the following routine to my project:
Sub LoadUserForm()
ufErrorLookup.Show
Close FileNumber
End Sub
This would display the user form, and close the file after the user form
has been closed. I guess that's not a bad way to do it, but I think that
closing the file through the Close event of a form (if such a thing
exists) would be cleaner.
Is there a Close event for user forms? If so, what is the first line (I
tried "Private Sub UserForm_Close()" and "Private Sub UserForm_Exit()")?
--Tom