ByRef Argument type mismatch with Boolean

calendar_today Asked Feb 13, 2014
thumb_up 9 upvotes
history Updated April 16, 2026

Question posted 2014 ยท +2 upvotes

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?

Accepted answer +9 upvotes

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

Top access-vba Q&A (6)

+9 upvotes ranks this answer #7 out of 12 access-vba solutions on this site .