Results 1 to 3 of 3
  1. #1
    Join Date
    Oct 2003

    Unanswered: How can I call function even when the parameters might be empty? I get an #ERROR

    In the ControlSource of an unbound text box called "Commission" I have the following:

    pendingAmount1 and pendingProduct1 are also text boxes but they are bound to fields in my database table. The problem is that when I leave either of those two fields empty, my function (CalculateCommission) is never called and the text box says "#ERROR".

    How can I fix this so it just stays blank?

    My function (CalculateComission) checks for nulls in the parameters, but this function is never even called before the "#ERROR" is displayed...

  2. #2
    Join Date
    Jul 2003
    In the function itself, you need to change the passed in arguments to optional

    Function CalculateCommission(Optional Param1, Optional Param2) As Variant

    Have the function return a Null if the Params are null
    Inspiration Through Fermentation

  3. #3
    Join Date
    Nov 2004
    out on a limb
    Provided Answers: 59
    To expand on RedNeckgeek's answer

    If you are potentially passing null values to a function then the functions must be of type variant, the return type doesn't matter that much, especailly if you handle the trap for nulls insiode the parameter

    RNG's answer should work as the default datatype fo vb / vba is variant.

Posting Permissions

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