Results 1 to 5 of 5
  1. #1
    Join Date
    Sep 2009
    Posts
    11

    Unanswered: Method syntax and brackets

    Methods of some objects, example the DoCmd object, seem to be syntactically incorrect if round brackets are used, eg
    DoCmd.GoToRecord , , acNewRec is correct, and
    DoCmd.GoToRecord (, , acNewRec) is not, whereas some other methods seem to require the brackets, eg
    Me.PSet(intI, sngMidPt)

    I also note that method invocations that return an object, eg
    ' Create child label control for text box.
    Set ctlLabel = CreateControl(frm.Name, acLabel, , _
    ctlText.Name, "NewLabel", intLabelX, intLabelY)

    seem to require the round brackets.

    What is the rule and where do I look it up? Any ideas folks?

  2. #2
    Join Date
    May 2009
    Posts
    258
    VB doesn't allow parentheses when calling Sub's unless you preface the call with the Call statement. For example, the following is a valid use:
    Code:
    Call DoCmd.GoToRecord(, , acNewRec)
    When a function call returns a value and you want to obtain that value, you'll need to use parentheses.

    With your PSet call, you aren't actually using parentheses on the function, the parentheses are used as a parameter. In other words, (intI, sngMidPt) is a essentially treated as a single parameter in PSet. For example, the following is a valid call:
    Code:
    Me.PSet (intI, sngMidPt), vbBlue
    Basically, it's easiest to skip the parentheses unless it is a function that you are trying to capture the return value for.

    Regards,

    Ax

  3. #3
    Join Date
    Sep 2009
    Posts
    11
    Thanks very much. Nicely stated.
    Any recommendation for a reference on this syntax? I had a bit of a poke around MSDN and didn't get anything conclusive.

  4. #4
    Join Date
    May 2009
    Posts
    258
    Chapter 4: Working with Objects and Collections
    Quote Originally Posted by MSDN
    Many methods take one or more arguments. An argument provides the method with additional information for its operation. If the method returns a value or an object, you must enclose its argument list in parentheses; otherwise you should omit the parentheses.

  5. #5
    Join Date
    Sep 2009
    Posts
    11
    Thanks a lot. Doesn't get much clearer than that.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •