The the ( ) and [ ] are not interchangeable. They just happened to produce the same results in the example you gave.
Parens ()
The () can be used to indicate a function. For Example.
SomeFunction() 'without parms
SomeFunction(aParm) 'with parms
() can be used to order the preference in a formula. For example. a * b - c is different than a * (b - c).
() can be used to indicate a subquery within a query. For example. Select a, b, (select c from tabb) as c from taba.
Brackets[]
[] is usually used to define a name with spaces. For example the field name "user name" would requre [user name] to define the field in many cases.
[] can be used to indicate a literal in a mask. For example. [#] would be to treat the # as a literal instead of a mask character.
These are just some uses but hopefully you get the idea.
The ( ) are used the same way you would in a math calculation (x+y)*2 = z. They Group calulations/statements together.
On the other hand [ ] is used to identify form, report, field, or control names.
For Example, if you have a Field Named My Field Num 1
To identify it you would use [My Field Num 1]
If you didn't Access would read it as [My][Field][Num][1] and return an error. This is why it is highly recomended that you don't use spaces in form, report, field, or control names.
Without spaces MyFieldNum1 is the same as [MyFieldNum1]
In your example MsgBox(strUser) and MsgBox[strUser] the reasion they both worked is because the () and the [] were ignored.
MsgBox strUser would of worked as well.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.