Using functions with optional argumernts in reports

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.
 
M

Marshall Barton

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)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top