Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

To ! or to . : That is the question!

Status
Not open for further replies.

Melagan

MIS
Nov 24, 2004
443
US
Would someone be able to point me to a good VB resource that describes the correct practices of when to use ! or . when referenceing objects and controls in VB?

ex:

Code:
If Me![txtMyDate] > Date() Then
 strTemp = "Future"
End If

Code:
If Me.txtMyDate > Date() Then
 strTemp = "Future"
End If

Which is correct? Why? Thank you!

~Melagan
______
"It's never too late to become what you might have been.
 
This can open up a can of worms, but both are correct. I am a big dot user others are Bang supporters. There is a pretty good disussion in the Access Desktop Developers Handbook by Litwin and Getz.

Here are some finer points.
1) You can reference a variable in dot notation but not in bang. For example

private function myName (ctrlName as string,frmName as string)
msgbox forms(frmName).controls(ctrlName).name
end function

2)In query parameters you have to use Bang.

Letwin and Getz suggest that you use Dot notation. The bigger problem is that people mix the two. But probably the biggest problem I have seen is that VB has default properties so most people do not understand what is going on.

forms.item("frmName").controls.item("ctrlName").value
is usually written as
forms("frmName")("ctrLName")

because "item" is the default of a collection, "controls" is the default property of a form, and "value" is the default of a control. So most people drop the defaults.
 
forms.item("frmName").controls.item("ctrlName").value
is usually written as
forms("frmName")("ctrLName")

Or as
Forms!frmName!ctrLName ' ;-)
 
Actually to be balanced
Forms![frmName].Controls![ctlName]
can be written as
Form![frmName]![ctlName]

As PHV shows there are defaults for both notation.
One more finer point. If you use Dot notation you get the benefit of Intelisense, not with bang.
 
So far on what I've read on the thread Remou linked and subsequent message boards, the big disadvantage with the DOT notation is that if you change your forms recordset and the control you're referencing with DOT notation is unbound, you'll run into problems. Otherwise, the advantage of intelisense probably outweighs the above disadvantage for a new programmer like myself.

~Melagan
______
"It's never too late to become what you might have been.
 
And to open the Pandora's box, do a google search for bang vs dot vba access

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top