Using functions with optional argumernts in reports

  • Thread starter Thread starter Steven Knopf
  • Start date Start date
S

Steven Knopf

How do I use a report to call a function where the function's first
parameter is optional and I want to leave it blank in the report?

My function is declared thus:

Public Function foo(Optional bar1 As Integer = 0, Optional bar2 As Integer =
0) As Integer

and I want to call it in a report thus:

=foo(,1)

but when I enter this in the report design I get the error message:

"The expression you entered contains invalid syntax.
You may have entered a comma without a preceding value or identifier"

Well yes I have, and that's what I want to do.

Any ideas how to achieve this in Access 2002 greatly appreciated.
 
Steven said:
How do I use a report to call a function where the function's first
parameter is optional and I want to leave it blank in the report?

My function is declared thus:

Public Function foo(Optional bar1 As Integer = 0, Optional bar2 As Integer =
0) As Integer

and I want to call it in a report thus:

=foo(,1)

but when I enter this in the report design I get the error message:

"The expression you entered contains invalid syntax.
You may have entered a comma without a preceding value or identifier"

I guess you have run into another difference between the VBA
environment and the Expression Service. The Expression
Service just doesn't understand named arguments and optional
arguments.

Either follow Duane's advice or use code to populate the
text box.
Me.txtBox = foo(,1)
 
Back
Top