IGNORE CONDITION WHEN CHECKBOXES NOT USED

B

BillA

This code is to create a filter string for Allen Browne’s search form. I
would like to add code that would look at a number of checkboxes and, if none
were checked, bypass or ignore their corresponding “If†conditions, possibly
using a “GoTo†statement? In other words; if a checkbox (or checkboxes) =
True Then execute otherwise skip this code continue with the procedure.

Here is a snippet of my code:

If (Me.chk24A) = True Then
strWhere = strWhere & "([24A]= True) AND "
ElseIf Me.chk24A = 0 Then
strWhere = strWhere & "([24A] = False) AND "
End If

If (Me.chk24B) = True Then
strWhere = strWhere & "([24B]= True) AND "
ElseIf Me.chk24B = 0 Then
strWhere = strWhere & "([24B] = False) AND "
End If

If (Me.chk67E) = True Then
strWhere = strWhere & "([67E]= True) AND "
ElseIf Me.chk67E = 0 Then
strWhere = strWhere & "([67E] = False) AND "
End If
……………………….
If Not IsNull(Me.txtRStartDate) Then
strWhere = strWhere & "([DateReceived] >= " &
Format(Me.txtRStartDate, conJetDate) & ") AND "
End If

If Not IsNull(Me.txtREndDate) Then 'Less than the next day.
strWhere = strWhere & "([DateReceived] < " & Format(Me.txtREndDate +
1, conJetDate) & ") AND "
End If
………………………
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then 'Nah: there was nothing in the string.
MsgBox "No criteria", vbInformation, "Nothing to do."
Else 'Yep: there is something there, so remove the "
AND " at the end.
strWhere = Left$(strWhere, lngLen)
'For debugging, remove the leading quote on the next line. Prints to
Immediate Window (Ctrl+G).
'Debug.Print strWhere

End If
End SubThank you for any assistance.
Bill
 
O

OldPro

This code is to create a filter string for Allen Browne's search form. I
would like to add code that would look at a number of checkboxes and, if none
were checked, bypass or ignore their corresponding "If" conditions, possibly
using a "GoTo" statement? In other words; if a checkbox (or checkboxes) =
True Then execute otherwise skip this code continue with the procedure.

Here is a snippet of my code:

If (Me.chk24A) = True Then
strWhere = strWhere & "([24A]= True) AND "
ElseIf Me.chk24A = 0 Then
strWhere = strWhere & "([24A] = False) AND "
End If

If (Me.chk24B) = True Then
strWhere = strWhere & "([24B]= True) AND "
ElseIf Me.chk24B = 0 Then
strWhere = strWhere & "([24B] = False) AND "
End If

If (Me.chk67E) = True Then
strWhere = strWhere & "([67E]= True) AND "
ElseIf Me.chk67E = 0 Then
strWhere = strWhere & "([67E] = False) AND "
End If
............................
If Not IsNull(Me.txtRStartDate) Then
strWhere = strWhere & "([DateReceived] >= " &
Format(Me.txtRStartDate, conJetDate) & ") AND "
End If

If Not IsNull(Me.txtREndDate) Then 'Less than the next day.
strWhere = strWhere & "([DateReceived] < " & Format(Me.txtREndDate +
1, conJetDate) & ") AND "
End If
...........................
lngLen = Len(strWhere) - 5
If lngLen <= 0 Then 'Nah: there was nothing in the string.
MsgBox "No criteria", vbInformation, "Nothing to do."
Else 'Yep: there is something there, so remove the "
AND " at the end.
strWhere = Left$(strWhere, lngLen)
'For debugging, remove the leading quote on the next line. Prints to
Immediate Window (Ctrl+G).
'Debug.Print strWhere

End If
End Sub>>><<<<

Thank you for any assistance.
Bill

Just put the entire section that deals with the checkboxes into an IF
THEN statement like the following:
IF (Me.chk24A) = True OR (Me.chk24B) = True OR (Me.chk25A) = True OR
(Me.chk26) = True THEN
' Do the sql string building
ENDIF
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top