Re: UserForm Is A Class



Once again I am plagued by Gremlins. For some unfathomable reason the code
I was using didn't like the term mboolCancel. I went back to Peters code
and created a form exactly to his instruction using mboolCancel. No joy.

I then created mirror statements in the form using the terms "mResult" and
"Result." I dimmed out the the exist mboolCancel and Cancel terms and it
worked. I then systematically altered term names and as when I changed
mboolCancel to mCancel the code as follows works as intended:

Public Sub MagicFormDiscussion()
Dim myFrm As oFrm6
Set myFrm = New oFrm6
Load myFrm
myFrm.Show
If myFrm.Cancel Then
MsgBox "Form was canceled"
Else
MsgBox "Form exited normally"
End If
MsgBox "Form complete"
Unload myFrm
Set myFrm = Nothing
End Sub

Option Explicit
Private mCancel As Boolean
Private Sub CmdCancel_Click()
mCancel = True
Me.Hide
End Sub
Private Sub cmdOK_Click()
mCancel = False
Me.Hide
End Sub
Public Property Get Cancel() As Boolean
Cancel = mCancel
End Property

Can anyone offer an explanation of what could have caused this? Thanks.

--
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.

Greg Maxey wrote:
> I just finished reading a skull splitting discussion about "Magic
> Forms" and UserForms being Classes, etc, etc.
>
> One of the arguments put forth is that UserForms are classes and
> should be used as such.
>
> Quote: "Take the situation where you need to know in the code that
> loads the form whether the user pressed Cancel or OK." The author
> proposed that the solution was to extend the form by creating a read
> only property called "Cancel." He went on to provide about half the
> code necessary to do this and I can't figure out the rest.
>
> I have tried to construct a workable code from samples I have of
> created of another property in a class module. It simply isn't
> working. My question is how do you do what the author above (Peter
> Hewett) proposed. I have the code I attempted with an asterisk to
> the right of the lines Peter listed in his article. I get a compile
> error on the line:
> If myFrm.Cancel Then *
> "Method or DataMemeber not found"
>
> Thanks
>
> The code
> Public Sub MagicFormDiscussion() *
> Dim myFrm As oFrm6 * Set
> myFrm = New oFrm6 * Load
> myFrm
> myFrm.Cancel = False
> myFrm.Show
> *
> If myFrm.Cancel Then *
> MsgBox "Form was canceled" *
> Else
> *
> MsgBox "Form exited normally" *
> End If
> *
> MsgBox "Form complete" *
> Unload myFrm
> *
> Set myFrm = Nothing * End
> Sub
> *
>
>
>
>
> The UserForm (Simple form with two command buttons)
>
> Option Explicit
> Public mboolCancel As Boolean *
> Private Sub CmdCancel_Click() *
> mboolCancel = True *
> Me.Hide
> End Sub *
> Private Sub CmdOK_Click() *
> mboolCancel = False *
> Me.Hide
> End Sub *
> Private Property Get Cancel() As Boolean
> *
> Cancel = mboolCancel
> *
> End Property
> *
> Public Property Let Cancel(NewValue As Boolean)
> mboolCancel = NewValue
> End Property
> *


.


Loading