如何正确查询是否在Access中从Excel中选中checkbox

Excel中的用户窗体上的checkbox6确定查询的select条件。 我需要使用checkbox6的True / False属性来查询位于Access表中的列[Archived]。 例如,如果在用户表单上检查了checkbox6,则[存档]列被查询为“真”值。 列[存档]是数据types是/否。 我已经尝试了“真”和“假”,还有-1和0,但似乎并不奏效。 请看下面我的代码,并build议如何使这项工作。

谢谢

Dim sar4 As String sar4 = "False" SQLwhere = "WHERE " If Len(sar2 & vbNullString) <> 0 Then If CheckBox7 = True Then SQLwhere = SQLwhere & "[MDL_Comments].[AA_change] = '" & sar2 & "' AND " Else SQLwhere = SQLwhere & "[MDL_Comments].[AA_change] LIKE '" & "%" & sar2 & "%" & "' AND " End If End If If CheckBox6 = True Then SQLwhere = SQLwhere & "[MDL_Table1].[Archived] = '" & sar4 & "' AND " End If StrSql = "SELECT * FROM [MDL_Comments] " 'Remove the last AND applicable If SQLwhere = "WHERE " Then SQLwhere = "" Else SQLwhere = Left(SQLwhere, Len(SQLwhere) - 5) End If StrSql = StrSql & SQLwhere 

我认为问题是你的variables使用单引号 – ('“&sar4&”')。 这会将variables设置为一个string,而不pipe分配给它的值如何。