Advantage to full object reference

williamlove

Registered User.
Local time
Today, 07:38
Joined
Feb 9, 2006
Messages
37
I noticed that somewhere along the line I no longer had to put the full reference to an object. For example, when I first coded my project five or six years ago (using Access XP or 2000) I had to do this:

Application.Forms!frmContacts.Controls!imgContactPicture.Picture = sFullPath & "\" & File.Name

but now I can omit the preamble and just do this:

imgContactPicture.Picture = sFullPath & "\" & File.Name

Can you tell me when/why this requirement changed and if there is any performance advantage to either?
 
I believe Application has always been understood.

Controls is the default collection on a form so you can leave it out.
Note however if a control by the name is not found then Access will happliy operate on a field by that name in the form's Recordset. This can have a very different outcome from expected.

If you refer to an object from another object on the same form then you can generally use just its name. However I have seen Access get confused so I tend to spell it out if there are controls by the same name on other forms. Once again watch for confusion between recordset field and controls.

In VBA you can get a away with just the name of a contol on the same form but it is bad practice. Always use Me! to be sure if the object is on the form.

The full name is the fastest because Access will knows exactly what is required by simply reading the reference without checking defaults. But the code gets cumbersome so there is a tradeoff.
 

Users who are viewing this thread

Back
Top Bottom