Referencing Controls on a Form (Dot v Bang)

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32661

    Referencing Controls on a Form (Dot v Bang)

    Originally posted by Denburt
    ...First whenever reffering to a control on a form you are currently in then you should always refer to it by using Me!

    Such as: Me!txtPassword. SetFocus
    ...
    You sound as if you know where you're coming from.
    Without hijacking the thread too much, What is your position on Me.Control versus Me!Control?
    Until recently, I would have said Me! was the correct way (both work generally of course). Then I considered that, although the controls are not defined properties of an Access.Form class, they are defined properties of the Form_YourFormNa me 'derived' class. I'd be interested in your comments.
  • Denburt
    Recognized Expert Top Contributor
    • Mar 2007
    • 1356

    #2
    NeoPa
    Until recently? Changed your oppinion... Unless there is something in the most recent version that i'm unaware of and from what I know it is basically the proper way of coding. I have inherited many databases over the years and have had issues with such coding practices.

    Here are some different ways of refering to controls.
    I have read articles that explicitly state that ME!Control is quicker than me.controls("Co ntrol") or other methods although I do use me(myVariable) quite often to change properties on a number of controls for dynamic purposes.

    Comment

    • NeoPa
      Recognized Expert Moderator MVP
      • Oct 2006
      • 32661

      #3
      Originally posted by Denburt
      NeoPa
      Until recently? Changed your oppinion... Unless there is something in the most recent version that i'm unaware of and from what I know it is basically the proper way of coding. I have inherited many databases over the years and have had issues with such coding practices.
      Yes. Recently, after seeing it used both ways, I tried to figure out for myself which is the 'correct' way. MS often provide more than one way to reference something and this is no exception.
      Originally posted by Denburt
      Here are some different ways of refering to controls.
      I have read articles that explicitly state that ME!Control is quicker than me.controls("Co ntrol") or other methods although I do use me(myVariable) quite often to change properties on a number of controls for dynamic purposes.
      My interest is not so much in the comparison between Me! & various other methods (No arguments with performance issues quoted btw), but between Me! & Me. specifically.
      Thanks for this link. It does sound as if the Me! is absolutely the 'most' correct way to specify an individual named instance of a control. Unfortunately, it still leaves questions unanswered.
      1. Why does Me. work at all?
      2. Why does the properties list only display in the VBA window when Me. is used?
      3. If the designed form in a database (Let's call it [frmThis] for convenience) is a derived class (From the Form class) then the controls on the form are properties of the [Form_frmThis] class itself surely - as well as being members of (but not restricted to) the Controls collection?

      I can't help feeling that someone has missed something somewhere (Yes, even someone from MS itself possibly - Internal communication is rarely perfect in large organisations at the best of times).

      Before I sign off, let me thank you for responding. Though I rarely accept anything at face value, I still appreciate your response :)

      Comment

      • Denburt
        Recognized Expert Top Contributor
        • Mar 2007
        • 1356

        #4
        LOL, Yes this had me for a long time and since I am self taught and using programming for more years than I want to count and currently on a long term contract for office automation. I tend to do as much research as possible for things (ANYTHING) that get under my claw.

        OK from what I understand it is a property but also an object however when you are referring to it as a property you would use the me. as an object me! yada yada Therefore me!mycontrol.se tfocus should be a gaurantee where me.mycontrol generally shouldn't but sometimes will (I am guessing auto correct).

        1. OK although not a hundred percent but pretty sure that the reason me. works when referring to it as an object is because of MS accesses flexibility and the autocorrect functions of the program. Since this would have to be taken into consideration i am quite sure that Me! would not only be more direct but quicker.

        2. The period lets the program know that you are accessing the properties of the object you are using thus the properties window is displayed.

        3. If I understand correctly I believe I agreed earlier in this post.

        You are quite welcome and I am more than happy to respond I hope you don't mind me quoting you but I also rarely accept anything at face value, and I am more than happy to share my views and or knowledge. Thanks for the questions.
        :)

        Comment

        • NeoPa
          Recognized Expert Moderator MVP
          • Oct 2006
          • 32661

          #5
          Denburt,
          I'm sorry I'll have to move this post later as it seems it's less straightforward than I anticipated. It can be done mind, but I need to rush out shortly so will do it later.
          I'll give better consideration to your (obviously quite thorough) answer then too if I may. I look forward to it. In fact I may print a hard-copy so won't have to wait so long :)

          Comment

          • MMcCarthy
            Recognized Expert MVP
            • Aug 2006
            • 14387

            #6
            Very interesting discussion guys!

            Denburt if you get the time could you put an article together for the articles forum here. I can then create a link to it in the Tutorials on Access and VBA
            thread.

            Mary

            Comment

            • Rabbit
              Recognized Expert MVP
              • Jan 2007
              • 12517

              #7
              We could always run a simulation to see whether Me! or Me. is faster. Say access the property 100,000 times and compare the time it takes to finish.

              Comment

              • NeoPa
                Recognized Expert Moderator MVP
                • Oct 2006
                • 32661

                #8
                Originally posted by Denburt
                LOL, Yes this had me for a long time and since I am self taught and using programming for more years than I want to count and currently on a long term contract for office automation. I tend to do as much research as possible for things (ANYTHING) that get under my claw.

                OK from what I understand it is a property but also an object however when you are referring to it as a property you would use the me. as an object me! yada yada Therefore me!mycontrol.se tfocus should be a gaurantee where me.mycontrol generally shouldn't but sometimes will (I am guessing auto correct).

                1. OK although not a hundred percent but pretty sure that the reason me. works when referring to it as an object is because of MS accesses flexibility and the autocorrect functions of the program. Since this would have to be taken into consideration i am quite sure that Me! would not only be more direct but quicker.

                2. The period lets the program know that you are accessing the properties of the object you are using thus the properties window is displayed.

                3. If I understand correctly I believe I agreed earlier in this post.

                You are quite welcome and I am more than happy to respond I hope you don't mind me quoting you but I also rarely accept anything at face value, and I am more than happy to share my views and or knowledge. Thanks for the questions.
                :)
                Right.
                Back to my post at last :)
                It seems to me, without wishing to flog a dead horse, the the crux of the question is "Is it a property of the derived form object - or not?"
                Your answer to question 1 is certainly a possibility, as I know that Access is very forgiving, when it can be. This is merely evidence for it being a possibility though, it doesn't so much support the position as fail to undermine it.
                However, as you say yourself in your answer to question 2, the period triggers a list of properties to be shown and Me. shows all the created controls in the list. This seems to me to imply (quite strongly actually) that, even though controls can be referenced via the Controls collection (Using ! to indicate a shortcut syntax if preferred), they are nevertheless properties in their own right.
                I presume, from your answer to question 3, that you're happy that they are, indeed, direct properties of the object. Does this mean that you're comfortable with the Me. syntax generally? (I'm not trying to put words into your mouth ;))

                Mary,
                There is another post (the last one) in the other thread that really belongs in here. If you know how to do that easily, could you move it across. The only way that I could think of to do that would be to merge then resplit the threads.

                Rabbit,
                Unless both syntax versions were examples of late-binding, I'm not sure that any difference in time would be reflective of the issues we're discussing. It's a neat idea though :)

                Comment

                • MMcCarthy
                  Recognized Expert MVP
                  • Aug 2006
                  • 14387

                  #9
                  Originally posted by NeoPa
                  Mary,
                  There is another post (the last one) in the other thread that really belongs in here. If you know how to do that easily, could you move it across. The only way that I could think of to do that would be to merge then resplit the threads.
                  Done.

                  For future reference, split out the posts into a temp thread then merge the temp thread with this one.

                  Mary

                  Comment

                  • NeoPa
                    Recognized Expert Moderator MVP
                    • Oct 2006
                    • 32661

                    #10
                    That's a good idea. I was thinking I'd have to merge before re-splitting. Having a Blond moment.
                    Unlucky on the rugby result btw - I was rooting for you. We were cr*p :(

                    Comment

                    • MMcCarthy
                      Recognized Expert MVP
                      • Aug 2006
                      • 14387

                      #11
                      Originally posted by NeoPa
                      That's a good idea. I was thinking I'd have to merge before re-splitting. Having a Blond moment.
                      Unlucky on the rugby result btw - I was rooting for you. We were cr*p :(
                      Yeah I guess it just wasn't meant to be. The last try by France, try or no try?

                      Comment

                      • NeoPa
                        Recognized Expert Moderator MVP
                        • Oct 2006
                        • 32661

                        #12
                        Originally posted by mmccarthy
                        Yeah I guess it just wasn't meant to be. The last try by France, try or no try?
                        Much as I hated to see it, I'm sure it was a try.

                        Comment

                        • Denburt
                          Recognized Expert Top Contributor
                          • Mar 2007
                          • 1356

                          #13
                          O.K. Mary yes I would love to put together an article for you I would like to finish a little research first and verify it in a few more tests.

                          OK Rabbit this ones for you.
                          Right now its late but here is the early results of my tests.

                          Using Forms!Main_Menu !FormsBut took merely 12 sec

                          Using Forms!Main_Menu .FormsBut took 15 sec

                          Rran it 4 times both ways same results exactly, I still have a few more things in mind to try though.
                          This was a toggle button on a form btw.

                          Code:
                          Private Sub DoMe()
                          Dim Cnt As Long
                          Do Until Cnt = 100000
                          If Forms!Main_Menu.FormsBut = 0 Then
                          Forms!Main_Menu!FormsBut = -1
                          Else
                          Forms!Main_Menu!FormsBut = 0
                          End If
                          Cnt = Cnt + 1
                          Loop
                          End Sub

                          Comment

                          • NeoPa
                            Recognized Expert Moderator MVP
                            • Oct 2006
                            • 32661

                            #14
                            Inspired to check this out for myself, I used the following code :
                            Code:
                            Private Sub chkVoy2_Click()
                                Dim lngIdx As Long
                            
                                Debug.Print Now()
                                For lngIdx = 1 To 500000
                                    Me!chkVoy2 = Not Me!chkVoy2
                                Next lngIdx
                                Debug.Print Now()
                                For lngIdx = 1 To 500000
                                    Me.chkVoy2 = Not Me.chkVoy2
                                Next lngIdx
                                Debug.Print Now()
                            End Sub
                            I found that, depending on where I put the various elements, the differences varied.
                            The last set I got was :
                            Code:
                            20/03/2007 12:55:15
                            20/03/2007 12:55:59
                            20/03/2007 12:56:44
                            ...but every other time there was a 2/3 second gap with the '.' version always taking longer. This is merely an interesting exercise as far as I'm concerned though, as I don't see it having any bearing on the fundamental issue.
                            Another point worth making though, is that the Me! version (on Access 2000 at least) DID bring up the list of controls available, contrary to what I posted earlier.

                            Comment

                            • Denburt
                              Recognized Expert Top Contributor
                              • Mar 2007
                              • 1356

                              #15
                              I presume, from your answer to question 3, that you're happy that they are, indeed, direct properties of the object. Does this mean that you're comfortable with the Me. syntax generally? (I'm not trying to put words into your mouth )
                              First I wanted to make sure I clarified this for you, um no. Yes I do agree that they are considered a property of that form, however calling an object using a properties syntax just rubs me wrong to say the least.

                              Most of my apps are usually resource hogs to begin with so if there is anything I can to streamline it and get an extra millisecond of time I try to do it. I have been looking and searching and racking my brain to see if there is a way to use the control as a property of the form yet I am still coming up stumped so far.

                              Give me just a little more time and I will make that post for you Mary I just like to be sure I do my research and I always like to back up my opinions with facts.

                              Comment

                              Working...