B
BruceM
After much searching online I have found some information in VBA Help about
using optional arguments in a user-defined function, but I cannot find
anything to find why adding an optional argument would make the function
stop working when I call it from the event property. Here are some details,
in case my terminology is unclear.
The function builds a filter string that is used to filter the recordset.
It works as it should. However, in one instance I need a modified approach
when making a selection from one of the combo boxes that is used to select
the elements of the filter. Here is the function title (or whatever it's
called):
Public Function SelFilter(lngID As Long) As String
On the Property Sheet for a combo box I have the following for the After
Update event:
=SelFilter([cboFind])
In other cases the function is called in code (because the event has to do
several things).
My idea was to add an optional boolean to the function:
Public Function SelFilter(lngID As Long, Optional blnSel as Boolean) As
String
or
Public Function SelFilter(lngID As Long, Optional blnSel as Boolean = False)
As String
From what I can tell, this works only if I am calling the function from
code. That is, in an event procedure I can have:
SelFilter(Me.cboFind, False)
or
SelFilter(Me.cboFind)
Either one works.
However, on the property sheet, this doesn't even call the function:
=SelFilter([cboFind])
I put a break point at the function title, but the code never ran. However,
when I did this:
=SelFilter([cboFind], False)
The function worked.
What I am getting from this is that optional arguments cannot be left blank
when calling the function from the property sheet. In other words, all
arguments, even optional ones, are required when calling the function from
the property sheet. If this is documented I cannot find it.
I am using Access 2003.
using optional arguments in a user-defined function, but I cannot find
anything to find why adding an optional argument would make the function
stop working when I call it from the event property. Here are some details,
in case my terminology is unclear.
The function builds a filter string that is used to filter the recordset.
It works as it should. However, in one instance I need a modified approach
when making a selection from one of the combo boxes that is used to select
the elements of the filter. Here is the function title (or whatever it's
called):
Public Function SelFilter(lngID As Long) As String
On the Property Sheet for a combo box I have the following for the After
Update event:
=SelFilter([cboFind])
In other cases the function is called in code (because the event has to do
several things).
My idea was to add an optional boolean to the function:
Public Function SelFilter(lngID As Long, Optional blnSel as Boolean) As
String
or
Public Function SelFilter(lngID As Long, Optional blnSel as Boolean = False)
As String
From what I can tell, this works only if I am calling the function from
code. That is, in an event procedure I can have:
SelFilter(Me.cboFind, False)
or
SelFilter(Me.cboFind)
Either one works.
However, on the property sheet, this doesn't even call the function:
=SelFilter([cboFind])
I put a break point at the function title, but the code never ran. However,
when I did this:
=SelFilter([cboFind], False)
The function worked.
What I am getting from this is that optional arguments cannot be left blank
when calling the function from the property sheet. In other words, all
arguments, even optional ones, are required when calling the function from
the property sheet. If this is documented I cannot find it.
I am using Access 2003.