CODE
Private Sub cmdReport_Click()
Dim rptSOP As String
Dim strFilter As String
strFilter = vbNullString
rptSOP = "SOPTraining"
strFilter = "[DocID]=" & cmbDocument.Value & " "
If chk1.Value <> "1" And chk1.Value <> "-1" Then
strFilter = strFilter & " AND [TeamID]<>1 "
End If
If chk2.Value <> "1" And chk2.Value <> "-1" Then
strFilter = strFilter & " AND [TeamID]<>2 "
End If
If chk3.Value <> "1" And chk3.Value <> "-1" Then
strFilter = strFilter & " AND [TeamID]<>3 "
End If
If chk4.Value <> "1" And chk4.Value <> "-1" Then
strFilter = strFilter & " AND [TeamID]<>4 "
End If
If chk5.Value <> "1" And chk5.Value <> "-1" Then
strFilter = strFilter & " AND [TeamID]<>5 "
End If
If chk6.Value <> "1" And chk6.Value <> "-1" Then
strFilter = strFilter & " AND [TeamID]<>6 "
End If
If chk7.Value <> "1" And chk7.Value <> "-1" Then
strFilter = strFilter & " AND [TeamID]<>7 "
End If
If chk8.Value <> "1" And chk8.Value <> "-1" Then
strFilter = strFilter & " AND [TeamID]<>8 "
End If
If chk9.Value <> "1" And chk9.Value <> "-1" Then
strFilter = strFilter & " AND [TeamID]<>36 "
End If
If chk0.Value <> "1" And chk0.Value <> "-1" Then
strFilter = strFilter & " AND [TeamID]<>37 "
End If
If Me.chkInclude.Value = "1" Or Me.chkInclude.Value = "-1" Then
DoCmd.OpenReport "SOPTraining2", acViewNormal, , strFilter, acHidden
Report_SOPTraining2.OrderBy = "[Last Name] "
Report_SOPTraining2.OrderByOn = True
Else
DoCmd.OpenReport rptSOP, acViewNormal, , strFilter, acHidden
Report_SOPTraining.OrderBy = "[Last Name] "
Report_SOPTraining.OrderByOn = True
End If
End Sub
Private Sub cmdTemplate_Click()
Dim rptTemplate As String
Dim strFilterTemplate As String
strFilterTemplate = vbNullString
rptTemplate = "SOPTraining-blank"
strFilterTemplate = "[DocID]=" & cmbDocument.Value
If chk1.Value <> "1" And chk1.Value <> "-1" Then
strFilterTemplate = strFilterTemplate & " AND [TeamID]<>1 "
End If
If chk2.Value <> "1" And chk2.Value <> "-1" Then
strFilterTemplate = strFilterTemplate & " AND [TeamID]<>2 "
End If
If chk3.Value <> "1" And chk3.Value <> "-1" Then
strFilterTemplate = strFilterTemplate & " AND [TeamID]<>3 "
End If
If chk4.Value <> "1" And chk4.Value <> "-1" Then
strFilterTemplate = strFilterTemplate & " AND [TeamID]<>4 "
End If
If chk5.Value <> "1" And chk5.Value <> "-1" Then
strFilterTemplate = strFilterTemplate & " AND [TeamID]<>5 "
End If
If chk6.Value <> "1" And chk6.Value <> "-1" Then
strFilterTemplate = strFilterTemplate & " AND [TeamID]<>6 "
End If
If chk7.Value <> "1" And chk7.Value <> "-1" Then
strFilterTemplate = strFilterTemplate & " AND [TeamID]<>7 "
End If
If chk8.Value <> "1" And chk8.Value <> "-1" Then
strFilterTemplate = strFilterTemplate & " AND [TeamID]<>8 "
End If
If chk9.Value <> "1" And chk9.Value <> "-1" Then
strFilterTemplate = strFilterTemplate & " AND [TeamID]<>36 "
End If
If chk0.Value <> "1" And chk0.Value <> "-1" Then
strFilterTemplate = strFilterTemplate & " AND [TeamID]<>37 "
End If
If Me.chkInclude.Value = "1" Or Me.chkInclude.Value = "-1" Then
DoCmd.OpenReport "SOPTraining-blank2", acViewNormal, , strFilterTemplate, acHidden
[Report_SOPTraining-blank2].OrderBy = "[Last Name] "
[Report_SOPTraining-blank2].OrderByOn = True
Else
DoCmd.OpenReport rptTemplate, acViewNormal, , strFilterTemplate, acHidden
[Report_SOPTraining-blank].OrderBy = "[Last Name] "
[Report_SOPTraining-blank].OrderByOn = True
End If
Dim rptSOP As String
Dim strFilter As String
strFilter = vbNullString
rptSOP = "SOPTraining"
strFilter = "[DocID]=" & cmbDocument.Value & " "
If chk1.Value <> "1" And chk1.Value <> "-1" Then
strFilter = strFilter & " AND [TeamID]<>1 "
End If
If chk2.Value <> "1" And chk2.Value <> "-1" Then
strFilter = strFilter & " AND [TeamID]<>2 "
End If
If chk3.Value <> "1" And chk3.Value <> "-1" Then
strFilter = strFilter & " AND [TeamID]<>3 "
End If
If chk4.Value <> "1" And chk4.Value <> "-1" Then
strFilter = strFilter & " AND [TeamID]<>4 "
End If
If chk5.Value <> "1" And chk5.Value <> "-1" Then
strFilter = strFilter & " AND [TeamID]<>5 "
End If
If chk6.Value <> "1" And chk6.Value <> "-1" Then
strFilter = strFilter & " AND [TeamID]<>6 "
End If
If chk7.Value <> "1" And chk7.Value <> "-1" Then
strFilter = strFilter & " AND [TeamID]<>7 "
End If
If chk8.Value <> "1" And chk8.Value <> "-1" Then
strFilter = strFilter & " AND [TeamID]<>8 "
End If
If chk9.Value <> "1" And chk9.Value <> "-1" Then
strFilter = strFilter & " AND [TeamID]<>36 "
End If
If chk0.Value <> "1" And chk0.Value <> "-1" Then
strFilter = strFilter & " AND [TeamID]<>37 "
End If
If Me.chkInclude.Value = "1" Or Me.chkInclude.Value = "-1" Then
DoCmd.OpenReport "SOPTraining2", acViewNormal, , strFilter, acHidden
Report_SOPTraining2.OrderBy = "[Last Name] "
Report_SOPTraining2.OrderByOn = True
Else
DoCmd.OpenReport rptSOP, acViewNormal, , strFilter, acHidden
Report_SOPTraining.OrderBy = "[Last Name] "
Report_SOPTraining.OrderByOn = True
End If
End Sub
Private Sub cmdTemplate_Click()
Dim rptTemplate As String
Dim strFilterTemplate As String
strFilterTemplate = vbNullString
rptTemplate = "SOPTraining-blank"
strFilterTemplate = "[DocID]=" & cmbDocument.Value
If chk1.Value <> "1" And chk1.Value <> "-1" Then
strFilterTemplate = strFilterTemplate & " AND [TeamID]<>1 "
End If
If chk2.Value <> "1" And chk2.Value <> "-1" Then
strFilterTemplate = strFilterTemplate & " AND [TeamID]<>2 "
End If
If chk3.Value <> "1" And chk3.Value <> "-1" Then
strFilterTemplate = strFilterTemplate & " AND [TeamID]<>3 "
End If
If chk4.Value <> "1" And chk4.Value <> "-1" Then
strFilterTemplate = strFilterTemplate & " AND [TeamID]<>4 "
End If
If chk5.Value <> "1" And chk5.Value <> "-1" Then
strFilterTemplate = strFilterTemplate & " AND [TeamID]<>5 "
End If
If chk6.Value <> "1" And chk6.Value <> "-1" Then
strFilterTemplate = strFilterTemplate & " AND [TeamID]<>6 "
End If
If chk7.Value <> "1" And chk7.Value <> "-1" Then
strFilterTemplate = strFilterTemplate & " AND [TeamID]<>7 "
End If
If chk8.Value <> "1" And chk8.Value <> "-1" Then
strFilterTemplate = strFilterTemplate & " AND [TeamID]<>8 "
End If
If chk9.Value <> "1" And chk9.Value <> "-1" Then
strFilterTemplate = strFilterTemplate & " AND [TeamID]<>36 "
End If
If chk0.Value <> "1" And chk0.Value <> "-1" Then
strFilterTemplate = strFilterTemplate & " AND [TeamID]<>37 "
End If
If Me.chkInclude.Value = "1" Or Me.chkInclude.Value = "-1" Then
DoCmd.OpenReport "SOPTraining-blank2", acViewNormal, , strFilterTemplate, acHidden
[Report_SOPTraining-blank2].OrderBy = "[Last Name] "
[Report_SOPTraining-blank2].OrderByOn = True
Else
DoCmd.OpenReport rptTemplate, acViewNormal, , strFilterTemplate, acHidden
[Report_SOPTraining-blank].OrderBy = "[Last Name] "
[Report_SOPTraining-blank].OrderByOn = True
End If
And my queries are all a slight variation of this:
CODE
SELECT DISTINCT [Last Name]+", "+[First Name] AS Expr1, Employees.TeamID, TrainEmpDoc.EmpID, TrainEmpDoc.DocID, TrainEmpDoc.Date AS DocDate, Documents.Title, Documents.[Effective Date], Lookup.Value, Employees.Active, Employees.[Last Name]
FROM (TrainEmpAct INNER JOIN (((TrainEmpDoc INNER JOIN Documents ON TrainEmpDoc.DocID = Documents.ID) INNER JOIN Employees ON TrainEmpDoc.EmpID = Employees.ID) INNER JOIN Lookup ON Employees.TeamID = Lookup.ID) ON TrainEmpAct.EmpID = Employees.ID) INNER JOIN ActDocs ON (TrainEmpDoc.DocID = ActDocs.DocID) AND (TrainEmpAct.ActID = ActDocs.ActID) AND (Documents.ID = ActDocs.DocID)
WHERE (((Employees.Active)=1) AND ((TrainEmpAct.Date) Is Not Null) AND ((TrainEmpAct.ActID) Is Not Null))
ORDER BY Employees.[Last Name];
FROM (TrainEmpAct INNER JOIN (((TrainEmpDoc INNER JOIN Documents ON TrainEmpDoc.DocID = Documents.ID) INNER JOIN Employees ON TrainEmpDoc.EmpID = Employees.ID) INNER JOIN Lookup ON Employees.TeamID = Lookup.ID) ON TrainEmpAct.EmpID = Employees.ID) INNER JOIN ActDocs ON (TrainEmpDoc.DocID = ActDocs.DocID) AND (TrainEmpAct.ActID = ActDocs.ActID) AND (Documents.ID = ActDocs.DocID)
WHERE (((Employees.Active)=1) AND ((TrainEmpAct.Date) Is Not Null) AND ((TrainEmpAct.ActID) Is Not Null))
ORDER BY Employees.[Last Name];
(I have tried this with the order by in the query before hand and without)
The weird thing is that it does infact order the results of the report.. the problem is that it always does it in descending order when I need it in ascending order. Even If I specify ASC on the OrderBy in the code, it still has no effect. I have tried applying the OrderBy to both Expr1 and just Last Name - still the same results. I will also post up a picture of my query incase that helps out a bit.
Wondering if maybe anyone has any idea as to why it could be acting strangely like this.
Also, I know the code is probably messy.. this was one of the first things I had to do when I started getting back into VBA. Plan on going back and eventually reworking all this and cleaning it up.