Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to declare optional function argument with empty array default value in VBA?

I am trying to build the routine below. The last argument of the routine is an optional array, by default it should have two empty strings. The declaration below doesn't work, it gives me this error: Compile error: Constant expression required

Public Sub CreateReport(rpt As Report, rptSelectFLDS As Variant, _
                        rptWhereConds As Dictionary, _
                        Optional rptTopSelect As Variant = Array("", ""))
like image 982
user2395238 Avatar asked Feb 01 '26 22:02

user2395238


1 Answers

How about just checking to see if the argument IsMissing()?

Public Sub CreateReport(rpt As Report, rptSelectFLDS As Variant, _
                        rptWhereConds As Dictionary, _
                        Optional rptTopSelect As Variant)

    If IsMissing(rptTopSelect) Then rptTopSelect = Array("", "")
like image 143
RubberDuck Avatar answered Feb 04 '26 12:02

RubberDuck



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!