I have a form with 7 checkboxes, each checkbox is a status: Open, Closed, Rejected, Postponed, Working, Duplicated and Testing
The value of checkbox can be True or False.
Now I would like to have the value of the checkbox to be concatenated in a SQL statement in VBA:
Dim Status As String
If (Open.value = True) Then Status = " status = 'Open'" End If
If (Postponed.value = True) Then Status = " or status = 'Postponed'" End If
If (Closed.value = True) Then Status = " or status = 'Closed'" End If
If (Rejected.value = True) Then Status = " or status = 'Rejected'" End If
If (Working.value = True) Then Status = " or status = 'Working'" End If
If (Duplicated.value = True) Then Status = " or status = 'Duplicated'" End If
If (Testing.value = True) Then Status = " or status = 'Testing'" End If
sqlstatement = "select * from cr where " & status
The issue with above code is that it is kinda hard coded. Meaning that if open.value is not true, then the whole statement is wrong. So how to make it dynamic to assemble only the criterias in where (any checkbox can be selected or dis-selected)?