Private Function TemplateComparison(WorkFlowTemplate As Integer) As DAO.Recordset
On Error GoTo ErrorHandle
Dim qry1SQL As String
qry1SQL = "SELECT tblWorkFlowTemplates.MasterProcessID, tblWorkFlowAssignmentsDetail.WorkFlowAssignmentID, tblWorkFlowTemplates.ProcessSequence," & _
" tblWorkFlowTemplates.TemplateMasterID, tblWorkFlowAssignmentsDetail.Completed" & _
" FROM tblWorkFlowAssignmentsDetail INNER JOIN tblWorkFlowTemplates ON" & _
" tblWorkFlowAssignmentsDetail.WorkFlowProcessID = tblWorkFlowTemplates.WorkFlowProcessID" & _
" WHERE tblWorkFlowAssignmentsDetail.WorkFlowAssignmentID = " & mWorkFlowAssignmentID & _
" ORDER BY tblWorkFlowTemplates.ProcessSequence;"
Dim qry1 As QueryDef
Set qry1 = CurrentDb.CreateQueryDef("CurrentTemplate", qry1SQL)
Dim qry2SQL As String
qry2SQL = "SELECT tblWorkFlowTemplates.MasterProcessID, tblWorkFlowTemplates.ProcessSequence," & _
" tblWorkFlowTemplates.TemplateMasterID, tblWorkFlowTemplates.WorkFlowProcessID" & _
" From tblWorkFlowTemplates" & _
" WHERE tblWorkFlowTemplates.TemplateMasterID = " & WorkFlowTemplate & _
" ORDER BY tblWorkFlowTemplates.ProcessSequence;"
Set qry2 = CurrentDb.CreateQueryDef("NewTemplate", qry2SQL)
Dim templateSQL As String
templateSQL = "SELECT NewTemplate.ProcessSequence, NewTemplate.MasterProcessID, NewTemplate.WorkFlowProcessID" & _
" FROM CurrentTemplate RIGHT JOIN NewTemplate ON CurrentTemplate.MasterProcessID =" & _
" NewTemplate.MasterProcessID" & _
" WHERE (((CurrentTemplate.MasterProcessID) Is Null)" & _
" OR ((CurrentTemplate.Completed) = False))" & _
" ORDER BY NewTemplate.ProcessSequence"
Dim rst As DAO.Recordset
Set rst = CurrentDb.OpenRecordset(templateSQL)
Set TemplateComparison = rst
Set rst = Nothing
CurrentDb.QueryDefs.Delete qry1.Name
CurrentDb.QueryDefs.Delete qry2.Name
ExitHandle:
Exit Function
ErrorHandle:
MsgBox Err.Description
DoCmd.SetWarnings (True)
Resume ExitHandle
End Function
|