Istari
Istari

Reputation: 3973

ByRef Argument type mismatch with Boolean

I have some vba code in an Access form which produces a "ByRef Argument type mismatch" error when called under the following circumstances.

I have a small function

NullAndHide(ctl as control,displayitem as Boolean) 

which works as expected when I call it like so.

Call NullAndHide(Me.Control,True)

However, if I use the following case statement to try to set the value of displayitem based on another control:

Dim PerPersonOption, PerRoomOption As Boolean

    Select Case PriceType_ID
Case Is = 1 'Per Person
    PerPersonOption = True
    PerRoomOption = False
Case Is = 2 'Per Room
    PerPersonOption = False
    PerRoomOption = True
End Select

And then

Call NullAndHide(Me.Control,PerPersonOption) I get the error:

ByRef Argument type mismatch

I've tested the the value of PerPersonOption with

msgBox PerPersonOption 

and it returns the correct boolean value.

My function expects a Boolean, I'm giving it a Boolean - So why am I getting this error?

Upvotes: 4

Views: 1663

Answers (1)

Dmitry Pavliv
Dmitry Pavliv

Reputation: 35853

When declaring Dim PerPersonOption, PerRoomOption As Boolean only PerRoomOption is type of Boolean, but PerPersonOption is Variant.

Try to use Dim PerPersonOption As Boolean, PerRoomOption As Boolean

enter image description here

Upvotes: 8

Related Questions