Passing Optional Arguments to Function

M

Mark Maeker

I have setup the function shown below. I am trying to use
it in a query as shown
Balance: ReceivableInvoiceBalance(InvoiceID, ,PaymentID)

I get the following error message:
The expression you entered contains invalid syntax;
You may have entered a comma without a preceding value or
identifier.

The problem is that it will not let me omit the second
argument.

Public Function ReceivableInvoiceBalance(lngInvoiceID As
Long, Optional datEndingDate As Date, Optional
lngPaymentID As Long) As Currency
On Error GoTo FunError
 
M

Marshall Barton

Mark said:
I have setup the function shown below. I am trying to use
it in a query as shown
Balance: ReceivableInvoiceBalance(InvoiceID, ,PaymentID)

I get the following error message:
The expression you entered contains invalid syntax;
You may have entered a comma without a preceding value or
identifier.

The problem is that it will not let me omit the second
argument.

Public Function ReceivableInvoiceBalance(lngInvoiceID As
Long, Optional datEndingDate As Date, Optional
lngPaymentID As Long) As Currency
On Error GoTo FunError
.
.
.
FunExit:
Exit Function

FunError:
MsgBox Err.Description
Resume FunExit

End Function

Can anyone tell me what I am doing wrong or if this is a
BUG in Access?

In my limited experience using optional arguments in the SQL
environment, missing arguments can only be at the end of the
argument list.

I only tried to do this once and got around the error you're
seeing by coding the function to test for Null as well
Missing. Then I could call the function this way:

ReceivableInvoiceBalance(InvoiceID, Null, PaymentID)

to get the desired result.
 
M

Mark Maeker

-----Original Message-----
Mark said:
I have setup the function shown below. I am trying to use
it in a query as shown
Balance: ReceivableInvoiceBalance(InvoiceID, ,PaymentID)

I get the following error message:
The expression you entered contains invalid syntax;
You may have entered a comma without a preceding value or
identifier.

The problem is that it will not let me omit the second
argument.

Public Function ReceivableInvoiceBalance(lngInvoiceID As
Long, Optional datEndingDate As Date, Optional
lngPaymentID As Long) As Currency
On Error GoTo FunError
.
.
.
FunExit:
Exit Function

FunError:
MsgBox Err.Description
Resume FunExit

End Function

Can anyone tell me what I am doing wrong or if this is a
BUG in Access?

In my limited experience using optional arguments in the SQL
environment, missing arguments can only be at the end of the
argument list.

I only tried to do this once and got around the error you're
seeing by coding the function to test for Null as well
Missing. Then I could call the function this way:

ReceivableInvoiceBalance(InvoiceID, Null, PaymentID)

to get the desired result.

--
Marsh
MVP [MS Access]
.
That will work.
Thank-you!
 

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