0

Checkbox6 on a userform in Excel determines the selection criteria for a query. I need to use the property of checkbox6 True/False to query column [Archived] that is located in a table in Access. For example, if the Checkbox6 is checked on the userform the column [Archived] is queried for “True” values. The column [Archived] is data type Yes/No. I’ve tried both “True” and “False” and also -1 and 0 but it doesn’t seem to work. Please look at my code below and suggest how to make this work.

Thanks

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

1 Answer 1

1

I think the problem is your use of single quotes around your variable - ('" & sar4 & "'). This will set the variable to be a string regardless of the value you assign to it.

Sign up to request clarification or add additional context in comments.

6 Comments

Sorry, please clarify What do I need to change? Thanks
You have single quotes inside you double quotes < ' " & sar4 & " ' > remove the single quote so that you have just < " & sar4 & ">
How should I declare sar4? I changed the quotes but got the same error."no value given for one or more required parameters" Thanks
You can keep the variable as a string. I suspect there's an error somewhere else. Try replacing the variable with just the SQL string and take a look at the complete SQL string to check it.
Should I try True/False or 0/-1. I think the values are stored as -1 and 0 in Access, or am I wrong? Thanks
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.