You should use those commands in place of the one that you have.
If this is more than an academic question, you might be interested in the
following rant from one Malcolm Smith
Quote
By magic form I mean the practice of intantiating an object
implicitly.
So example, say you create a form class called frmLetter then the
wrong way to instantiate the form would be:
frmLetter.Show
This is because frmLetter is a CLASS and not an OBJECT. What happens
is that a default object is created. There are a load of issues with
this method.
The first is that the scope of such an implicit object is global.
Now, one of the whole point about writing proper code is that objects
and variables have their own scopes - all designed to be as tight as
possible.
If you go and bust the whole scope open then (a) it's bad programming
practice and (b) people can actually access the form from anywhere
within the code. Also, it goes to show other developers that the
programmer has a problem distinguishing between classes and objects.
Not good for one's reputation.
The other problem; one that I have seen time and time again is that
quite often the implicit object is not destroyed in memory if the same
template is run again within the same session. For example, the last
time I was called out to solve this problem was to a London Law Firm
who were complaining that the users were calling up a letter or fax
template and that the information entered in the fields last time were
there for the next letter.
The problem was with Magic Forms and the way that the programmer
called them. The answer is to create an object explicitly:
Dim oForm as frmLetter
Set oForm = New frmLetter
oForm.txtDate.Text = Format$(Date(), "d mmmm yyyy")
oForm.Show vbModal
' ----------------------------------
Unload oForm
Set oForm = Nothing
Then everything is nicely wrapped up at the end and there is nothing
horrible hanging about in memory afterwards.
It is not a co-incidence that in .Net magic forms are no longer
allowed. One has to create an explicit object. The general response
from the VB community was "finally they have fixed this".
Magic forms are one of the dreadful shortcuts and defaults permitted
(nay, encouraged) by Microsoft and they never, ever, should be used.
There are a number of these diseased defaults in Word and over the
course of the New Year I will itemise these on my web site.
But, please believe me that using magic forms (i.e. implicitly calling
the Class) is not good programming at all. I have not met anyone who
who disagrees with me and can put forward a valid reason. All of the
serious VB and VBA developers that I know and respect all say the same
thing "magic forms are a spawn of the devil and should be avoided".
Until someone can give me a good strong reason why magic forms are a
good idea this will be my stance. And, believe me, I and others
better than I have thought long and hard about this.
As an example of another diseased possibility in VB/VBA. Why on
earth is Option Explicit by default turned off?
Anyway, the only reason why I won't do the site now is that tomorrow
it's my birthday and I think that I deserve going out to celebrate
another year gone...
Unquote
--
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
How did you get the userform to show?
Try
Dim myform As YourFormName
Set myform = New YourFormName
myform.Show
Unload myform
Set myform = Nothing
--
Hope this helps.
Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.
Doug Robbins - Word MVP
- Åã¥Ü³Q¤Þ¥Î¤å¦r -
Hi,
I got the usrform to show by putting the following command in a macro,
say "activateform1", under the module in a project:
userform1.show false
May I ask where I should put your suggested commands? Should I put
them in a macro or a subroutine in a userform? Can you give me an
example? Thank you.
Mike