G
Greg Maxey
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
*
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
*