Jezebel,
In a UserForm I have:
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
In a project module I have:
Sub MagicFormDiscussion()
Dim myFrm As oUserForm
Set myFrm = New oUserForm
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
This is code I put togeher a year or so ago after discussing the topic with
you and Jonathan West.
Jonathan posted some informaton on pitfalls of Public declarations statement
earlier today. The form module in the code above uses a "Public" Property
Get. It won't work if it is Private. Is this a sound method or should I
look for another way to determine if a form is canceled?
Thanks

Signature
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
> Dim pForm as formB
>
[quoted text clipped - 32 lines]
>>
>> Thanks for your help.
Jezebel - 16 Mar 2007 03:06 GMT
Yes, that's exactly the way to do it. I haven't seen Jonathon's post, but
presumably he was referring to the danger of using declarations like
Public XYZ as whatever
because other modules can change the value any way they like. But the code
you have creates Cancel as a read-only property, which -- in this case,
anyway -- is what you want. For completeness, you might want to set mCancel
= FALSE in the form's Activate event, in case the form gets shown again,
rather than unloaded. (A principle of object-oriented coding is that an
object is not responsible for its own destruction.)
> Jezebel,
>
[quoted text clipped - 77 lines]
>>>
>>> Thanks for your help.
Greg Maxey - 16 Mar 2007 03:30 GMT
Ok thanks.

Signature
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
> Yes, that's exactly the way to do it. I haven't seen Jonathon's post,
> but presumably he was referring to the danger of using declarations
[quoted text clipped - 96 lines]
>>>>
>>>> Thanks for your help.
Jonathan West - 16 Mar 2007 13:17 GMT
> Jezebel,
>
[quoted text clipped - 38 lines]
> method or should I look for another way to determine if a form is
> canceled?
Public properties in UserForms or Class modules are fine. They (along with
public methods) are the means by which the form or class communicated with
the rest of your project.
If you declare a variable with the Public keyword on a UserForm or Class, it
acts as a read-write public property of that form or class. If you later
decide that you want to add some processing when the variable is set or read
from outside, it is easy enough to convert it into a Property Let/Get pair,
and the interface of the form or class to the outside world appears entirely
unchanged.
There are those who argue that it is better to start with a Property Let/Get
pair from the outset. I'm inclined that way in my own coding style, but I
accept that it is a matter of style, and need for this is dependent on the
complexity of the project you work on.
I was discussing in the General group yesterday the pitfalls of putting a
Public variable into an ordinary Module. They behave rather differently from
Public variables in classes or forms.

Signature
Regards
Jonathan West - Word MVP
www.intelligentdocuments.co.uk
Please reply to the newsgroup
Greg Maxey - 16 Mar 2007 21:57 GMT
Thanks Jonathan. Sometimes I get it, sometimes I don't. As the mere
mention of Class, Get, and Let can usually bring on a outbreak of hives,
this time I am not sure ;-).
I'll keep plugging away and one day the "blink" of complete comprehension
will finally occur.

Signature
Greg Maxey/Word MVP
See:
http://gregmaxey.mvps.org/word_tips.htm
For some helpful tips using Word.
>> Jezebel,
>>
[quoted text clipped - 58 lines]
> putting a Public variable into an ordinary Module. They behave rather
> differently from Public variables in classes or forms.
Jean-Guy Marcil - 16 Mar 2007 15:22 GMT
Greg Maxey was telling us:
Greg Maxey nous racontait que :
> Jezebel,
>
[quoted text clipped - 38 lines]
> sound method or should I look for another way to determine if a form
> is canceled?
I understand the principle of the Get/Let pair for creating read-only or
Read/Write properties.
But, in such simple cases (i.e. Was the form's Cancel button used or not?),
is it "dangerous" to use simply:
Option Explicit
Public mCancel As Boolean
Private Sub cmdCancel_Click()
mCancel = True
Me.Hide
End Sub
Private Sub cmdOK_Click()
mCancel = False
Me.Hide
End Sub
Sub MagicFormDiscussion()
Dim myFrm As oUserForm
Set myFrm = New oUserForm
myFrm.Show
If myFrm.mCancel Then
MsgBox "Form was canceled"
Else
MsgBox "Form exited normally"
End If
MsgBox "Form complete"
Unload myFrm
Set myFrm = Nothing
End Sub
The calling Sub will not change the value of mCancel (although it could)
just because it makes no sense to do that.
Or, for the sake of completeness and total security, is it recommended to
always use a Get statement instead?
I mean, I know we could write something like:
Sub MagicFormDiscussion()
Dim myFrm As oUserForm
Set myFrm = New oUserForm
myFrm.Show
myFrm.mCancel = True
If myFrm.mCancel Then
MsgBox "Form was canceled"
Else
MsgBox "Form exited normally"
End If
MsgBox "Form complete"
Unload myFrm
Set myFrm = Nothing
End Sub
But why would we?

Signature
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org
Jezebel - 16 Mar 2007 19:06 GMT
In this case it's not very dangerous, no. Obviously in practice there's no
harm in using a read/write property but only reading it; provided this is a
discipline you can maintain across your project (which you usually can if
it's reasonably small and you're the only person who touches the code). But
it's a poor practice none the less. If you're writing code that has to stay
in use for a while, or that will get maintained by others, the total effort
expended over the life of the project is minimised if you follow good coding
standards.
One part of which is to keep everything as modular as possible and to write
'defensive' code, that precludes the possibility of the error rather than
relying on memory and discipline to prevent it.
> Greg Maxey was telling us:
> Greg Maxey nous racontait que :
[quoted text clipped - 98 lines]
>
> But why would we?
Jean-Guy Marcil - 16 Mar 2007 19:46 GMT
Jezebel was telling us:
Jezebel nous racontait que :
> One part of which is to keep everything as modular as possible and to
> write 'defensive' code, that precludes the possibility of the error
> rather than relying on memory and discipline to prevent it.
Very true, especially if the project is later handled by some else.
Thanks for your thoughts.

Signature
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org
Does
pForm.Show vbModal
halt execution of
MyValue = pForm....
until pForm is hidden?
> Dim pForm as formB
>
[quoted text clipped - 32 lines]
> >
> > Thanks for your help.
Jezebel - 16 Mar 2007 03:08 GMT
I should have suggested that you read help on 'vbModal'. If you show the
form with Modal = true, execution in the calling function stops and waits
while the form is active (ie until it is hidden or unloaded); if modal is
false, execution continues immediately. Which you obviously don't want in
your case, because you'd be trying to read the form properties before the
user has had a chance to set them.
> Does
> pForm.Show vbModal
[quoted text clipped - 45 lines]
>> >
>> > Thanks for your help.
kMan - 16 Mar 2007 03:16 GMT
thanks a million...
I'll try it tonight.
> I should have suggested that you read help on 'vbModal'. If you show the
> form with Modal = true, execution in the calling function stops and waits
[quoted text clipped - 52 lines]
> >> >
> >> > Thanks for your help.