Option Compare Database
Private Function todoListQry(whereClause As String) As String
Dim selectClause As String
Dim selectClauseHard As String
Dim followupPersonClause As String
Dim orderClause As String
selectClause = "SELECT notes.priority, notes.FollowUpDate, Format([FollowUpDate],'mm/dd/yyyy') AS FollowUpDateTrunc, notes.created_at, notes.company_id, notes.followup_person_id, notes.author_id, notes.Notes, notes.person_id, notes.EntryId FROM notes"
selectClauseHard = "SELECT notes.priority, notes.FollowUpDate, Format([FollowUpDate],'mm/dd/yyyy') AS FollowUpDateTrunc, notes.created_at, notes.company_id, notes.followup_person_id, notes.author_id, notes.Notes, notes.person_id, notes.EntryId FROM notes"
followupPersonClause = "notes.followup_person_id = " & GetCurrentUserId()
orderClause = "notes.priority DESC , notes.FollowUpDate ASC;"
todoListQry = selectClause & " WHERE " & whereClause & " AND " & followupPersonClause & " ORDER BY " & orderClause
End Function
Private Function dateClause(dateQry As String, op As String) As String
dateClause = "Format(FollowUpDate, 'mm/dd/yyyy') " & op & " Format(" & dateQry & ",'mm/dd/yyyy')"
End Function
Private Function multiDateClause(dateStartQry As String, dateEndQry As String, firstOp As String, secondOp As String)
multiDateClause = dateClause(dateStartQry, firstOp) & " AND " & dateClause(dateEndQry, secondOp)
End Function
'--**************
Private Sub b_urgent_Click()
Me.resultsFrame.SourceObject = "FollowUp_bystaff"
Me.resultsFrame.Form.RecordSource = "qry_todolist_urgent" '--todoListQry(Notes.urgent = 1) '--THIS SHOULD ONLY GIVE US URGENT FOLLOWUPS REGARDLESS OF THE DATE
End Sub
Private Sub b_today_Click()
Me.resultsFrame.SourceObject = "FollowUp_bystaff"
Me.resultsFrame.Form.RecordSource = todoListQry(multiDateClause("Date()-1", "Date()", ">=", "<="))
End Sub
Private Sub b_last7_Click()
Me.resultsFrame.SourceObject = "FollowUp_bystaff"
Me.resultsFrame.Form.RecordSource = todoListQry(multiDateClause("Date()-6", "Date()", ">=", "<="))
End Sub
Private Sub b_month_Click()
Me.resultsFrame.SourceObject = "FollowUp_bystaff"
Me.resultsFrame.Form.RecordSource = todoListQry(multiDateClause("Date()-30", "Date()", ">=", "<="))
End Sub
Private Sub b_future_Click()
Me.resultsFrame.SourceObject = "FollowUp_bystaff"
Me.resultsFrame.Form.RecordSource = todoListQry(dateClause("Date()+1", ">="))
End Sub
Private Sub b_all_past_Click()
Me.resultsFrame.SourceObject = "FollowUp_bystaff"
Me.resultsFrame.Form.RecordSource = "qry_todolist_all" '--using the dateClause does not filter out nulls
End Sub
Private Sub b_level_1_Click()
Me.resultsFrame.SourceObject = "FollowUp_Level1"
Me.resultsFrame.Form.RecordSource = "select (FirstName + ' ' + LastName) as fullname, * from people where people.Filed = 20 ORDER BY people.LastCnct DESC"
End Sub
Private Sub b_safetysheet_Click()
Me.resultsFrame.SourceObject = "ActiveNoSafety"
Me.resultsFrame.Form.RecordSource = "SELECT timeline.EmployeeId, timeline.SafetySheet, people.Filed, timeline.company_id, timeline.start_date, timeline.assignment FROM timeline INNER JOIN people ON timeline.EmployeeId = people.EmployeeID WHERE (((timeline.SafetySheet)<>'true' Or (timeline.SafetySheet) Is Null) AND ((people.Filed)=5 Or (people.Filed)=8) AND ((timeline.assignment)='true')) ORDER BY timeline.start_date DESC;"
End Sub
Private Sub b_jillhead_Click()
Me.resultsFrame.SourceObject = "FollowUp_bystaff"
Me.resultsFrame.Form.RecordSource = "SELECT * From notes WHERE notes.followup_person_id = 77 And notes.FollowUpdate Is Not Null"
End Sub
Private Sub b_joe_references_Click()
Me.resultsFrame.SourceObject = "FollowUp_bystaff"
Me.resultsFrame.Form.RecordSource = "SELECT * From notes WHERE notes.followup_person_id = 84 And notes.FollowUpdate Is Not Null"
End Sub
Private Sub b_joehead_Click()
Me.resultsFrame.SourceObject = "FollowUp_bystaff"
Me.resultsFrame.Form.RecordSource = "SELECT * From notes WHERE notes.followup_person_id = 68 And notes.FollowUpdate Is Not Null"
End Sub
Private Sub b_close_Click()
DoCmd.Close
End Sub
Private Sub Form_Open(Cancel As Integer)
Me.resultsFrame.SourceObject = "FollowUp_bystaff"
Me.resultsFrame.Form.RecordSource = todoListQry(dateClause("Date()", "="))
End Sub