Results 1 to 5 of 5
  1. #1
    JustCallMeAl
    Guest

    Property Get/Let Part II (Word97 SR2)

    At this <A target="_blank" HREF=http://www.wopr.com/cgi-bin/w3t/showflat.pl?Cat=&Board=vb&Number=69245&page=1&view =expanded&sb=5&o=0&fpart=>thread</A>, was a discussion of using Property Get/Let in a UserForm. A lot of good information is there.

    I had decided that I would not use custom properties with a userform and go with createing and assigning module level variables to the values I was going to assign to the properties.

    Then this morning I decided that it would be too much work to convert this project.

    Unfortunately, VBA thought otherwise. Unbeknowns to me, when I tried to use the properties within the calling module (e.g., UserForm.UserClickedOK), I found that even though the form was loaded, the UserForm_Initialize event would fire! This would reset all the values to what was assigned in the Initialize event. <img src=/S/sad.gif border=0 alt=sad width=15 height=15>

    So, I thought, I will move all those assignments from the UserForm_Initialize to the UserForm_Activate event.

    Well, VBA still fired the Initialize event and now all the properties were empty--no values.

    So, it appears that using design-defined properties in a UserForm is not the best idea!

    <img src=/S/surrender.gif border=0 alt=surrender width=31 height=23>

  2. #2
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Property Get/Let Part II (Word97 SR2)

    <hr>I had decided that I would not use custom properties with a userform and go with createing and assigning module level variables to the values I was going to assign to the properties.<hr>
    I'm confused. Module level variables *are* custom properties even though they aren't created using the Property Let/Get approach.

    However, if you're assigning values to those variables/properties from the OnClick event of a button on the userform, then you must also be doing something that's reinitializing the properties. Why don't you post the code for your OnClick event so someone can figure out what's going on.
    Charlotte

  3. #3
    JustCallMeAl
    Guest

    Re: Property Get/Let Part II (Word97 SR2)

    We may be having a problem with terms.

    By "custom properties" I am meaning the ones I was setting up IN the UserForm by Property Get/Let. By module level variables, I am meaning what Geoff wrote about in the thread referenced above. When asked what he meant, his response was:

    <hr>I have a module1 and Userform1

    Module1:

    Option Explicit
    Public blnOK As Boolean

    Sub Show()
    blnOK = False
    UserForm1.Show
    MsgBox blnOK
    End Sub

    In Userform1:

    Option Explicit
    Private Sub cmdOK_Click()
    Module1.blnOK = True
    Me.Hide
    End Sub

    <hr>

    Does that clarifiy it for you?

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Property Get/Let Part II (Word97 SR2)

    In Geoff's code, blnOK is a public variable, but if it's in a class module (userform module) it's *also* a property of that object even though you don't use a Property Let to populate it. Since module1 is not the module for the userform, that blnOK is simply a public variable.

    If you declare the variable in userform1, it becomes a property of the userform and you can set it in the same routine that shows the userform by simply saying

    Userform1.blnOK = True

    It's really an issue of what scope the variable should have and how you plan to use it. I don't see anything here that's either an activate or initialize event, so I still don't know what specific problem you're having. <img src=/S/shrug.gif border=0 alt=shrug width=39 height=15>
    Charlotte

  5. #5
    JustCallMeAl
    Guest

    Re: Property Get/Let Part II (Word97 SR2)

    Come to find out, there were other problems with the code which may have led to the anamoly I mentioned above.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •