Hi, what I am trying to do is this:
I have a table which lists out business months with a business month start and business month end field.
I have a table which lists out quality incidents and the dates the incidents were found.
I would like to cycle through the dates in the quality incidents table one at a time and compare them to the business month date ranges in the business month table.
If a quality incident date does not fall in any of the business month date ranges, then debug.print that date and then test the next quality date, and so on.
What I have prints all quality dates which don't match the business month date range of the first record, and then it moves on.
Any help would be appreciated:
Dim dbs As Database
Dim rst As DAO.Recordset
Dim rstP As DAO.Recordset
Dim StSql As String
Dim stPoints As String
Dim pDate As Date
Dim dCounter As Integer
Dim pCounter As Integer
Dim x As Integer
Dim z As Integer
dCounter = DCount("[monStart]", "tblQirMonths") 'Get a count
pCounter = DCount("[qir]", "qir_table", "[qir] ='yes' AND [error_found_dt] Is Not Null AND [qi_points] >=0.5") 'Get a count
Set dbs = CurrentDb
StSql = "SELECT tblQirMonths.monStart, tblQirMonths.monEnd FROM tblQirMonths;" 'Business Month Dates
stPoints = "SELECT qir_table.qir, qir_table.error_found_dt, qir_table.qi_points FROM qir_table " & _
"WHERE qir_table.qir ='yes' AND qir_table.error_found_dt Is Not Null AND qir_table.qi_points>=0.5;" 'Quality Incidents
Set rst = dbs.OpenRecordset(StSql, dbOpenDynaset) 'Business Months
Set rstP = dbs.OpenRecordset(stPoints, dbOpenDynaset) 'Quality Points
rstP.MoveFirst 'Select first date found in the QI Table
For z = 1 To pCounter 'The number of records where Qir = Yes, the date is not null and has points assinged.
pDate = rstP("[error_found_dt]")
rst.MoveFirst 'Cycle through the table for business months.
For x = 1 To dCounter 'The number of entries in tblQir months
If Not (pDate >= rst("[monStart]") And pDate <= rst("[monEnd]")) Then
Debug.Print pDate
End If
rst.MoveNext
Next
rstP.MoveNext
Next
rst.Close
Set dbs = Nothing
Thanks, Dan
I have a table which lists out business months with a business month start and business month end field.
I have a table which lists out quality incidents and the dates the incidents were found.
I would like to cycle through the dates in the quality incidents table one at a time and compare them to the business month date ranges in the business month table.
If a quality incident date does not fall in any of the business month date ranges, then debug.print that date and then test the next quality date, and so on.
What I have prints all quality dates which don't match the business month date range of the first record, and then it moves on.
Any help would be appreciated:
Dim dbs As Database
Dim rst As DAO.Recordset
Dim rstP As DAO.Recordset
Dim StSql As String
Dim stPoints As String
Dim pDate As Date
Dim dCounter As Integer
Dim pCounter As Integer
Dim x As Integer
Dim z As Integer
dCounter = DCount("[monStart]", "tblQirMonths") 'Get a count
pCounter = DCount("[qir]", "qir_table", "[qir] ='yes' AND [error_found_dt] Is Not Null AND [qi_points] >=0.5") 'Get a count
Set dbs = CurrentDb
StSql = "SELECT tblQirMonths.monStart, tblQirMonths.monEnd FROM tblQirMonths;" 'Business Month Dates
stPoints = "SELECT qir_table.qir, qir_table.error_found_dt, qir_table.qi_points FROM qir_table " & _
"WHERE qir_table.qir ='yes' AND qir_table.error_found_dt Is Not Null AND qir_table.qi_points>=0.5;" 'Quality Incidents
Set rst = dbs.OpenRecordset(StSql, dbOpenDynaset) 'Business Months
Set rstP = dbs.OpenRecordset(stPoints, dbOpenDynaset) 'Quality Points
rstP.MoveFirst 'Select first date found in the QI Table
For z = 1 To pCounter 'The number of records where Qir = Yes, the date is not null and has points assinged.
pDate = rstP("[error_found_dt]")
rst.MoveFirst 'Cycle through the table for business months.
For x = 1 To dCounter 'The number of entries in tblQir months
If Not (pDate >= rst("[monStart]") And pDate <= rst("[monEnd]")) Then
Debug.Print pDate
End If
rst.MoveNext
Next
rstP.MoveNext
Next
rst.Close
Set dbs = Nothing
Thanks, Dan