best way to reference a form or control

scratch

Registered User.
Local time
Today, 04:47
Joined
May 10, 2005
Messages
98
I'm working in access 2002. I found these way to reference forms/controls. I was wondering which was the best way. Right now, I'm using the 2nd one since I had some compatablity problems with 2000. When I used the 3rd method and it seemed to solve it and still work in 2002. Are there significant advantages of using one over the overs?

Me.Address.Value
Forms("Clinic")("Address").Value
Forms![Clinic]![Address].Value
 
Within a form's class module, use the Me.fieldname style. You don't need the .value since the value property is the default and help tells you you can omit it. Be wary of shortcut reference methods that happen to work if Microsoft doesn't tell you that it is ok.

The other two styles, are used when referring to controls on some form other than the current one. Although if the form is a parent or child of the current form, you can still use the Me. style - Me.Parent.controlname or Me.subformcontrolname.Form!controlname.
 
Pat Hartman said:
You don't need the .value since the value property is the default

I disagree. I like to use the .value for 2 reasons. 1) It distinctly tells the program where to go (I think it saves some processing done by the application) 2) It tells the programmer what value is being pulled (not having to know what the default state is)
 
So does that mean that you use the long form of refererence for form controls also?
Forms!frmSubExpense.Controls!txtExpenseType

rather than:
Forms!frmSubExpense!txtExpenseType
 
It depends on the circumstance, but lately I've been doing

Forms("Form Name").Controls("Control Name")

I do this because it is easier to see what type of object is being called. Also, I am used to OOP in C++, so of course the dot is my first choice :) Finally, this way clearly seperates the name from the type. As a programmer, I find this better when reviewing code that I've written in the past.
 
According to Ken Getz in his Developer Handbook, Bangs and Dots should not be used where at all possible, as they are converted under the hood in Access

so...
Forms!MyForm!MyControl
becomes
Forms("MyForm")("MyControl")

Another point, ASP doesn't recognise Bangs, another reason to use parentheses & quotes
 
Last edited:

Users who are viewing this thread

Back
Top Bottom