Referencing Controls on a Form  | Administrator | | Join Date: Oct 2006 Location: London - UK
Posts: 16,173
| | Quote:
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_YourFormName 'derived' class. I'd be interested in your comments.
|  | Moderator | | Join Date: Mar 2007 Location: Louisiana
Posts: 1,218
| | | re: Referencing Controls on a Form
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("Control") or other methods although I do use me(myVariable) quite often to change properties on a number of controls for dynamic purposes. http://msdn2.microsoft.com/en-us/lib...ffice.11).aspx |  | Administrator | | Join Date: Oct 2006 Location: London - UK
Posts: 16,173
| | | re: Referencing Controls on a Form Quote:
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. Quote:
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("Control") 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. - Why does Me. work at all?
- Why does the properties list only display in the VBA window when Me. is used?
- 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 :)
|  | Moderator | | Join Date: Mar 2007 Location: Louisiana
Posts: 1,218
| | | re: Referencing Controls on a Form
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.setfocus 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.
:)
|  | Administrator | | Join Date: Oct 2006 Location: London - UK
Posts: 16,173
| | | re: Referencing Controls on a Form
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 :)
|  | Administrator | | Join Date: Aug 2006 Location: Dublin, Ireland
Posts: 11,114
| | | re: Referencing Controls on a Form
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
|  | Expert | | Join Date: Jan 2007 Location: California
Posts: 3,835
| | | re: Referencing Controls on a Form
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.
|  | Administrator | | Join Date: Oct 2006 Location: London - UK
Posts: 16,173
| | | re: Referencing Controls on a Form Quote:
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.setfocus 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 :)
|  | Administrator | | Join Date: Aug 2006 Location: Dublin, Ireland
Posts: 11,114
| | | re: Referencing Controls on a Form Quote:
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
|  | Administrator | | Join Date: Oct 2006 Location: London - UK
Posts: 16,173
| | | re: Referencing Controls on a Form
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 :(
|  | Administrator | | Join Date: Aug 2006 Location: Dublin, Ireland
Posts: 11,114
| | | re: Referencing Controls on a Form Quote:
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?
|  | Administrator | | Join Date: Oct 2006 Location: London - UK
Posts: 16,173
| | | re: Referencing Controls on a Form Quote:
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.
|  | Moderator | | Join Date: Mar 2007 Location: Louisiana
Posts: 1,218
| | | re: Referencing Controls on a Form
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. - 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
|  | Administrator | | Join Date: Oct 2006 Location: London - UK
Posts: 16,173
| | | re: Referencing Controls on a Form
Inspired to check this out for myself, I used the following 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 : - 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.
|  | Moderator | | Join Date: Mar 2007 Location: Louisiana
Posts: 1,218
| | | re: Referencing Controls on a Form Quote:
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.
|  | Administrator | | Join Date: Aug 2006 Location: Dublin, Ireland
Posts: 11,114
| | | re: Referencing Controls on a Form Quote:
Originally Posted by Denburt 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. No problem. If you don't get it right some argumentative members (not mentioning any names Ade) will feel honour bound to find the holes in it for you.
Mary
|  | Administrator | | Join Date: Oct 2006 Location: London - UK
Posts: 16,173
| | | re: Referencing Controls on a Form
I seem to come at this from the opposite direction. I would look to use a predefined property of a specific form (Object or otherwise) first as a property of the form. That's not to say I can only conceive of that way being correct. Quote:
Originally Posted by Denburt 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. I must be missing something here. I would think that using Me. would be referring to the control as a property of the form. I'm sure you must mean something different from what I understand you to be saying.
Anyway - it's nearly 19:00 so I should be getting off home :(
|  | Similar Microsoft Access / VBA bytes | | | Forums
Visit our community forums for general discussions and latest on Bytes
/bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 229,155 network members.
|