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

Top access-vba Q&A (6)
- Create a query dynamically through code in MSAccess 2003 [VBA] +19 (2008)
- MS Access RunCode Macro cannot find my procedure +15 (2013)
- VBA: Why must I set focus to control every time? +15 (2013)
- Equivalent cURL in VBA? +14 (2013)
- Retrieve column values of the selected row of a multicolumn Access listbox +12 (2011)
- Loop through all unbound controls on a form and clear data +11 (2013)
access-vba solutions on this site
.