named arguments vs un-named arguments
- Mainly a personal preference and for simple commands perhaps a bit redundant; however, for me I find that:
1) The order doesn't matter doesn't matter
+
DoCmd.Close ObjectName:=Me.Name, ObjectType:=acForm, Save:=acSaveNo
+
DoCmd.Close Save:=acSaveNo, ObjectType:=acForm,ObjectName:=Me.Name
+
DoCmd.Close ObjectType:=acForm,ObjectName:=Me.Name Save:=acSaveNo
Can't count the number of times when I've been in a hurry that I've started with the Title for a msgbox because that was what I was thinking about at that moment in time.
As of late I've been using the err.Raise method in my code so that my error-handler will take care of messages and drop to the clean-up if certain conditions are not handled so I have a Select-Case in these types of error traps with things like:
-
zStrMsg = Err.Number & vbcrlf & Err.Source & vbcrlf & Err.Description
-
'(...)
-
zStrMsg = zStrMsg & vbcrlf & "Do you want to override and commit action? (default [No])"
-
'
-
MsgBox Title:="Oh No Action is Prohibited!", Prompt:= zStrMsg, Buttons:= vbCritical+vbYesNo+vbDefaultButton2
I like to start with the title as it's an abstract of what the MsgBox is for in that context without having to dig back through my code for "(vbObjectError + 1)".
2) It makes it clear what your intent is/was (i.e: Err.Raise/MsgBox) for anyone following you for code maintenance without having to find the syntax reference for more complex code (I work with a lot of individuals that do not know nor care to learn any programing language - I'm a chemist by trade/training with a bit of math, (chem/civil)engineering, and compsci tossed in for spice)
3) You can do this:
DoCmd.OpenForm FormName:="SomeFrmName",OpenArgs:="StringHere"
Instead of
DoCmd.OpenForm "SomeFrmName",,,,,,"StringHere"
is The String a WhereCondition or a Open arguments
For example
DoCmd.OpenForm "SomeFrmName",,,,,,"Monkey=Chimp"
vs
DoCmd.OpenForm "SomeFrmName",WhereCondition:="Monkey='Chimp'"
While in one you could be troubleshooting for a "Month" if you thought you were passing a WhereCondtion clause in the second the intent is clear AND you know you need that extra set of quotes (yes, I've seen this done - extra/missing comma makes a difference - have you accidently deleted a comma and the code that was working stopped - ARRRGH)! Also, IM
VHO, it makes the code cleaner by removing all of those placeholders.
4)When explaining syntax to a inexperience user without the benefit of face-to-face it prevents any ambiguity in the explanation.