By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,665 Members | 1,576 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,665 IT Pros & Developers. It's quick & easy.

Referencing Controls on a Form (Dot v Bang)

NeoPa
Expert Mod 15k+
P: 31,530
...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.
Mar 16 '07 #1
Share this Question
Share on Google+
16 Replies


Denburt
Expert 100+
P: 1,356
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
Mar 16 '07 #2

NeoPa
Expert Mod 15k+
P: 31,530
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.
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.
http://msdn2.microsoft.com/en-us/lib...ffice.11).aspx
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 :)
Mar 16 '07 #3

Denburt
Expert 100+
P: 1,356
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.
:)
Mar 16 '07 #4

NeoPa
Expert Mod 15k+
P: 31,530
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 :)
Mar 16 '07 #5

MMcCarthy
Expert Mod 10K+
P: 14,534
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
Mar 17 '07 #6

Rabbit
Expert Mod 10K+
P: 12,369
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.
Mar 17 '07 #7

NeoPa
Expert Mod 15k+
P: 31,530
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 :)
Mar 17 '07 #8

MMcCarthy
Expert Mod 10K+
P: 14,534
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
Mar 17 '07 #9

NeoPa
Expert Mod 15k+
P: 31,530
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 :(
Mar 17 '07 #10

MMcCarthy
Expert Mod 10K+
P: 14,534
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?
Mar 17 '07 #11

NeoPa
Expert Mod 15k+
P: 31,530
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.
Mar 19 '07 #12

Denburt
Expert 100+
P: 1,356
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.

Expand|Select|Wrap|Line Numbers
  1. Private Sub DoMe()
  2. Dim Cnt As Long
  3. Do Until Cnt = 100000
  4. If Forms!Main_Menu.FormsBut = 0 Then
  5. Forms!Main_Menu!FormsBut = -1
  6. Else
  7. Forms!Main_Menu!FormsBut = 0
  8. End If
  9. Cnt = Cnt + 1
  10. Loop
  11. End Sub
Mar 20 '07 #13

NeoPa
Expert Mod 15k+
P: 31,530
Inspired to check this out for myself, I used the following code :
Expand|Select|Wrap|Line Numbers
  1. Private Sub chkVoy2_Click()
  2.     Dim lngIdx As Long
  3.  
  4.     Debug.Print Now()
  5.     For lngIdx = 1 To 500000
  6.         Me!chkVoy2 = Not Me!chkVoy2
  7.     Next lngIdx
  8.     Debug.Print Now()
  9.     For lngIdx = 1 To 500000
  10.         Me.chkVoy2 = Not Me.chkVoy2
  11.     Next lngIdx
  12.     Debug.Print Now()
  13. End Sub
I found that, depending on where I put the various elements, the differences varied.
The last set I got was :
Expand|Select|Wrap|Line Numbers
  1. 20/03/2007 12:55:15
  2. 20/03/2007 12:55:59
  3. 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.
Mar 20 '07 #14

Denburt
Expert 100+
P: 1,356
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.
Mar 20 '07 #15

MMcCarthy
Expert Mod 10K+
P: 14,534
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
Mar 20 '07 #16

NeoPa
Expert Mod 15k+
P: 31,530
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.
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 :(
Mar 20 '07 #17

Post your reply

Sign in to post your reply or Sign up for a free account.