Dude, bad post. Try word wrap. =)
SELECT tbl_downtime.Employee_Number, tbl_downtime.Machine_Stop, tbl_downtime.Machine_Start,
tbl_downtime.DownTime, tbl_downtime.Shift
FROM tbl_downtime
WHERE (((tbl_downtime.Machine_Start) Between [Forms]![F_Reports2].[txtStop] And
[Forms]![F_Reports2].[txtStart]) AND ((tbl_downtime.Shift)=IIf([Forms]![F_Reports2]![chk1]=0 And
[Forms]![F_Reports2]![chk2]=0 And [Forms]![F_Reports2]![chk3]=-1,"3",IIf([Forms]![F_Reports2]![chk1]=0 And
[Forms]![F_Reports2]![chk2]=-1 And [Forms]![F_Reports2]![chk3]=0,"2",IIf([Forms]![F_Reports2]![chk1]=-1 And
[Forms]![F_Reports2]![chk2]=0 And [Forms]![F_Reports2]![chk3]=0,"1",IIf([Forms]![F_Reports2]![chk1]=-1 And
[Forms]![F_Reports2]![chk2]=-1 And [Forms]![F_Reports2]![chk3]=0,"1" AND "2","0"))))));
It seems from looking at your combination of check boxes, that Check3 is never used to figure the state of the Shift. So this logic should do it for you:
Dim c1 As Boolean
Dim c2 As Boolean
Dim c3 As Boolean
Dim iShift As Integer
Dim sShift As String
Dim sSQL As String
c1 = Me.chk1
c2 = Me.chk2
c3 = Me.chk3
If c1 = False Then
If c2 = False Then
iShift = 3
Else
iShift = 2
End If
Else
If c2 = False Then
iShift = 1
Else
sShift = " 1 And 2"
End If
End If
If sShift <> "" Then
sSQL = "SELECT tbl_downtime.Employee_Number, tbl_downtime.Machine_Stop, tbl_downtime.Machine_Start, " & _
"tbl_downtime.DownTime, tbl_downtime.Shift " & _
"FROM tbl_downtime " & _
"WHERE (((tbl_downtime.Machine_Start) Between [Forms]![F_Reports2].[txtStop] And " & _
"[Forms]![F_Reports2].[txtStart]) AND [tbl_downtime.Shift] = 1 AND [tbl_downtime.Shift] = 2"
'I really think you mean 1 OR 2 here, not 1 AND 2
Else
sSQL = "SELECT tbl_downtime.Employee_Number, tbl_downtime.Machine_Stop, tbl_downtime.Machine_Start, " & _
"tbl_downtime.DownTime, tbl_downtime.Shift " & _
"FROM tbl_downtime " & _
"WHERE (((tbl_downtime.Machine_Start) Between [Forms]![F_Reports2].[txtStop] And " & _
"[Forms]![F_Reports2].[txtStart]) AND [tbl_downtime.Shift] = " & iShift
End If
Did that help?
mmcdonal
Look it up at:
http://wrox.books24x7.com