dharkangel
MIS
Hi everyone, I have this piece of code that I repeat below. It runs fine until it gets to the sixth iteration of the code (the part that says 'REPEAT CODE' area. I thought it may be a problem with the SQL for that sixth specific block of code but it wasn't. The runtime error occurs on the sixth iteration of the code no matter what variables are in the code. The error says 'Run-time error -2147217865 (80040e37): The Microsoft Jet database engine could not find the object ''. Make sure the object exists and that you specll its name and the path name correctly'
Dim etmRecordSet As New ADODB.Recordset 'create recordset var
Dim etmRecordSetCount As Integer 'create var to store record count of specific week data
Dim etmCombinedRecordSet As New ADODB.Recordset 'create recordset var
Dim etmCombinedRecordSetCount As Integer 'create var to store record count of specific week data
Dim eumRecordSet As New ADODB.Recordset 'create recordset var
Dim eumRecordSetCount As Integer 'create var to store record count of specific week data
Dim eumCombinedRecordSet As New ADODB.Recordset 'create recordset var
Dim eumCombinedRecordSetCount As Integer 'create var to store record count of specific week data
'*************************************************
'REPEAT CODE BEGIN
'ETM
'**************************************************
etmRecordSet.ActiveConnection = myConnection 'set recordset var
'set name of role from array
RoleName = RoleArray(1, 0)
'get the number of Assigned Actions for a given week, for ETM
mySQL = "SELECT DISTINCT (Replace(QPTActions.[Assigned To],',','')) AS Assignee, UserRoleData.Role " & _
"FROM QPTActions INNER JOIN UserRoleData ON UserRoleData.[Resource Name]=Replace(QPTActions.[Assigned To],',','') " & _
"WHERE DateValue(QPTActions.[Entry Date])<=DateValue('" & weekStart & "') And DateValue(QPTActions.[Close Date])>DateValue('" & weekStart & "') AND UserRoleData.Role='" & RoleName & "' " & _
"UNION SELECT DISTINCT (Replace(BarcelonaInternalActions.[Assign To],',','')) AS Assignee, UserRoleData.Role " & _
"FROM BarcelonaInternalActions INNER JOIN UserRoleData ON UserRoleData.[Resource Name]=Replace(BarcelonaInternalActions.[Assign To],',','') " & _
"WHERE DateValue(BarcelonaInternalActions.[Entry Date])<=DateValue('" & weekStart & "') And DateValue(BarcelonaInternalActions.[Close Date])>DateValue('" & weekStart & "') AND UserRoleData.Role='" & RoleName & "' " & _
"UNION " & _
"SELECT DISTINCT (Replace(RDActions.[Assigned To],',','')) AS Assignee, UserRoleData.Role " & _
"FROM RDActions INNER JOIN UserRoleData ON UserRoleData.[Resource Name]=Replace(RDActions.[Assigned To],',','') " & _
"WHERE DateValue(RDActions.[Entry Date])<=DateValue('" & weekStart & "') And DateValue(RDActions.[Close Date])>DateValue('" & weekStart & "') AND UserRoleData.Role='" & RoleName & "' " & _
"UNION SELECT DISTINCT (Replace(TokyoInternalActions.[Assigned To],',','')) AS Assignee, UserRoleData.Role " & _
"FROM TokyoInternalActions INNER JOIN UserRoleData ON UserRoleData.[Resource Name]=Replace(TokyoInternalActions.[Assigned To],',','') " & _
"WHERE DateValue(TokyoInternalActions.[Entry Date])<=DateValue('" & weekStart & "') And DateValue(TokyoInternalActions.[Close Date])>DateValue('" & weekStart & "') AND UserRoleData.Role='" & RoleName & "';"
'open the recordset of all the data from SQL statement
etmRecordSet.Open mySQL, , adOpenStatic
'get the record count
etmRecordSetCount = etmRecordSet.RecordCount
'set connection for second query
etmCombinedRecordSet.ActiveConnection = myConnection 'set recordset var
'get the number of Assigned Actions for a given week, for ETM
mySQL2 = "SELECT [Issue ID], Replace(QPTActions.[Assigned To],',','') AS Assignee, UserRoleData.Role " & _
"FROM QPTActions INNER JOIN UserRoleData ON UserRoleData.[Resource Name]=Replace(QPTActions.[Assigned To],',','') " & _
"WHERE DateValue(QPTActions.[Entry Date])<=DateValue('" & weekStart & "') And DateValue(QPTActions.[Close Date])>DateValue('" & weekStart & "') AND UserRoleData.Role='" & RoleName & "' " & _
"UNION SELECT [Issue ID], Replace(BarcelonaInternalActions.[Assign To],',','') AS Assignee, UserRoleData.Role " & _
"FROM BarcelonaInternalActions INNER JOIN UserRoleData ON UserRoleData.[Resource Name]=Replace(BarcelonaInternalActions.[Assign To],',','') " & _
"WHERE DateValue(BarcelonaInternalActions.[Entry Date])<=DateValue('" & weekStart & "') And DateValue(BarcelonaInternalActions.[Close Date])>DateValue('" & weekStart & "') AND UserRoleData.Role='" & RoleName & "' " & _
"UNION " & _
"SELECT [Issue ID], Replace(RDActions.[Assigned To],',','') AS Assignee, UserRoleData.Role " & _
"FROM RDActions INNER JOIN UserRoleData ON UserRoleData.[Resource Name]=Replace(RDActions.[Assigned To],',','') " & _
"WHERE DateValue(RDActions.[Entry Date])<=DateValue('" & weekStart & "') And DateValue(RDActions.[Close Date])>DateValue('" & weekStart & "') AND UserRoleData.Role='" & RoleName & "' " & _
"UNION SELECT [Issue ID], Replace(TokyoInternalActions.[Assigned To],',','') AS Assignee, UserRoleData.Role " & _
"FROM TokyoInternalActions INNER JOIN UserRoleData ON UserRoleData.[Resource Name]=Replace(TokyoInternalActions.[Assigned To],',','') " & _
"WHERE DateValue(TokyoInternalActions.[Entry Date])<=DateValue('" & weekStart & "') And DateValue(TokyoInternalActions.[Close Date])>DateValue('" & weekStart & "') AND UserRoleData.Role='" & RoleName & "';"
'open the recordset of all the data from SQL statement
etmCombinedRecordSet.Open mySQL2, , adOpenStatic
'get the record count
etmCombinedRecordSetCount = etmCombinedRecordSet.RecordCount
'*************************************************
'REPEAT CODE END
'**************************************************
'*************************************************
'REPEAT CODE BEGIN
'EUM
'**************************************************
eumRecordSet.ActiveConnection = myConnection 'set recordset var
'set name of role from array
RoleName = RoleArray(2, 0)
'get the number of Assigned Actions for a given week, for EUM
mySQL = "SELECT DISTINCT (Replace(QPTActions.[Assigned To],',','')) AS Assignee, UserRoleData.Role " & _
"FROM QPTActions INNER JOIN UserRoleData ON UserRoleData.[Resource Name]=Replace(QPTActions.[Assigned To],',','') " & _
"WHERE DateValue(QPTActions.[Entry Date])<=DateValue('" & weekStart & "') And DateValue(QPTActions.[Close Date])>DateValue('" & weekStart & "') AND UserRoleData.Role='" & RoleName & "' " & _
"UNION SELECT DISTINCT (Replace(BarcelonaInternalActions.[Assign To],',','')) AS Assignee, UserRoleData.Role " & _
"FROM BarcelonaInternalActions INNER JOIN UserRoleData ON UserRoleData.[Resource Name]=Replace(BarcelonaInternalActions.[Assign To],',','') " & _
"WHERE DateValue(BarcelonaInternalActions.[Entry Date])<=DateValue('" & weekStart & "') And DateValue(BarcelonaInternalActions.[Close Date])>DateValue('" & weekStart & "') AND UserRoleData.Role='" & RoleName & "' " & _
"UNION " & _
"SELECT DISTINCT (Replace(RDActions.[Assigned To],',','')) AS Assignee, UserRoleData.Role " & _
"FROM RDActions INNER JOIN UserRoleData ON UserRoleData.[Resource Name]=Replace(RDActions.[Assigned To],',','') " & _
"WHERE DateValue(RDActions.[Entry Date])<=DateValue('" & weekStart & "') And DateValue(RDActions.[Close Date])>DateValue('" & weekStart & "') AND UserRoleData.Role='" & RoleName & "' " & _
"UNION SELECT DISTINCT (Replace(TokyoInternalActions.[Assigned To],',','')) AS Assignee, UserRoleData.Role " & _
"FROM TokyoInternalActions INNER JOIN UserRoleData ON UserRoleData.[Resource Name]=Replace(TokyoInternalActions.[Assigned To],',','') " & _
"WHERE DateValue(TokyoInternalActions.[Entry Date])<=DateValue('" & weekStart & "') And DateValue(TokyoInternalActions.[Close Date])>DateValue('" & weekStart & "') AND UserRoleData.Role='" & RoleName & "';"
'open the recordset of all the data from SQL statement
eumRecordSet.Open mySQL, , adOpenStatic
'get the record count
eumRecordSetCount = eumRecordSet.RecordCount
'set connection for second query
eumCombinedRecordSet.ActiveConnection = myConnection 'set recordset var
'get the number of Assigned Actions for a given week, for EUM
mySQL2 = "SELECT [Issue ID], Replace(QPTActions.[Assigned To],',','') AS Assignee, UserRoleData.Role " & _
"FROM QPTActions INNER JOIN UserRoleData ON UserRoleData.[Resource Name]=Replace(QPTActions.[Assigned To],',','') " & _
"WHERE DateValue(QPTActions.[Entry Date])<=DateValue('" & weekStart & "') And DateValue(QPTActions.[Close Date])>DateValue('" & weekStart & "') AND UserRoleData.Role='" & RoleName & "' " & _
"UNION SELECT [Issue ID], Replace(BarcelonaInternalActions.[Assign To],',','') AS Assignee, UserRoleData.Role " & _
"FROM BarcelonaInternalActions INNER JOIN UserRoleData ON UserRoleData.[Resource Name]=Replace(BarcelonaInternalActions.[Assign To],',','') " & _
"WHERE DateValue(BarcelonaInternalActions.[Entry Date])<=DateValue('" & weekStart & "') And DateValue(BarcelonaInternalActions.[Close Date])>DateValue('" & weekStart & "') AND UserRoleData.Role='" & RoleName & "' " & _
"UNION " & _
"SELECT [Issue ID], Replace(RDActions.[Assigned To],',','') AS Assignee, UserRoleData.Role " & _
"FROM RDActions INNER JOIN UserRoleData ON UserRoleData.[Resource Name]=Replace(RDActions.[Assigned To],',','') " & _
"WHERE DateValue(RDActions.[Entry Date])<=DateValue('" & weekStart & "') And DateValue(RDActions.[Close Date])>DateValue('" & weekStart & "') AND UserRoleData.Role='" & RoleName & "' " & _
"UNION SELECT [Issue ID], Replace(TokyoInternalActions.[Assigned To],',','') AS Assignee, UserRoleData.Role " & _
"FROM TokyoInternalActions INNER JOIN UserRoleData ON UserRoleData.[Resource Name]=Replace(TokyoInternalActions.[Assigned To],',','') " & _
"WHERE DateValue(TokyoInternalActions.[Entry Date])<=DateValue('" & weekStart & "') And DateValue(TokyoInternalActions.[Close Date])>DateValue('" & weekStart & "') AND UserRoleData.Role='" & RoleName & "';"
'open the recordset of all the data from SQL statement
eumCombinedRecordSet.Open mySQL2, , adOpenStatic
'get the record count
eumCombinedRecordSetCount = eumCombinedRecordSet.RecordCount
'*************************************************
'REPEAT CODE END
'**************************************************
etc......
etmRecordSet.Close
etmCombinedRecordSet.Close
Set etmRecordSet = Nothing
Set etmCombinedRecordSet = Nothing
eumRecordSet.Close
eumCombinedRecordSet.Close
Set eumRecordSet = Nothing
Set eumCombinedRecordSet = Nothing
etc....
Dim etmRecordSet As New ADODB.Recordset 'create recordset var
Dim etmRecordSetCount As Integer 'create var to store record count of specific week data
Dim etmCombinedRecordSet As New ADODB.Recordset 'create recordset var
Dim etmCombinedRecordSetCount As Integer 'create var to store record count of specific week data
Dim eumRecordSet As New ADODB.Recordset 'create recordset var
Dim eumRecordSetCount As Integer 'create var to store record count of specific week data
Dim eumCombinedRecordSet As New ADODB.Recordset 'create recordset var
Dim eumCombinedRecordSetCount As Integer 'create var to store record count of specific week data
'*************************************************
'REPEAT CODE BEGIN
'ETM
'**************************************************
etmRecordSet.ActiveConnection = myConnection 'set recordset var
'set name of role from array
RoleName = RoleArray(1, 0)
'get the number of Assigned Actions for a given week, for ETM
mySQL = "SELECT DISTINCT (Replace(QPTActions.[Assigned To],',','')) AS Assignee, UserRoleData.Role " & _
"FROM QPTActions INNER JOIN UserRoleData ON UserRoleData.[Resource Name]=Replace(QPTActions.[Assigned To],',','') " & _
"WHERE DateValue(QPTActions.[Entry Date])<=DateValue('" & weekStart & "') And DateValue(QPTActions.[Close Date])>DateValue('" & weekStart & "') AND UserRoleData.Role='" & RoleName & "' " & _
"UNION SELECT DISTINCT (Replace(BarcelonaInternalActions.[Assign To],',','')) AS Assignee, UserRoleData.Role " & _
"FROM BarcelonaInternalActions INNER JOIN UserRoleData ON UserRoleData.[Resource Name]=Replace(BarcelonaInternalActions.[Assign To],',','') " & _
"WHERE DateValue(BarcelonaInternalActions.[Entry Date])<=DateValue('" & weekStart & "') And DateValue(BarcelonaInternalActions.[Close Date])>DateValue('" & weekStart & "') AND UserRoleData.Role='" & RoleName & "' " & _
"UNION " & _
"SELECT DISTINCT (Replace(RDActions.[Assigned To],',','')) AS Assignee, UserRoleData.Role " & _
"FROM RDActions INNER JOIN UserRoleData ON UserRoleData.[Resource Name]=Replace(RDActions.[Assigned To],',','') " & _
"WHERE DateValue(RDActions.[Entry Date])<=DateValue('" & weekStart & "') And DateValue(RDActions.[Close Date])>DateValue('" & weekStart & "') AND UserRoleData.Role='" & RoleName & "' " & _
"UNION SELECT DISTINCT (Replace(TokyoInternalActions.[Assigned To],',','')) AS Assignee, UserRoleData.Role " & _
"FROM TokyoInternalActions INNER JOIN UserRoleData ON UserRoleData.[Resource Name]=Replace(TokyoInternalActions.[Assigned To],',','') " & _
"WHERE DateValue(TokyoInternalActions.[Entry Date])<=DateValue('" & weekStart & "') And DateValue(TokyoInternalActions.[Close Date])>DateValue('" & weekStart & "') AND UserRoleData.Role='" & RoleName & "';"
'open the recordset of all the data from SQL statement
etmRecordSet.Open mySQL, , adOpenStatic
'get the record count
etmRecordSetCount = etmRecordSet.RecordCount
'set connection for second query
etmCombinedRecordSet.ActiveConnection = myConnection 'set recordset var
'get the number of Assigned Actions for a given week, for ETM
mySQL2 = "SELECT [Issue ID], Replace(QPTActions.[Assigned To],',','') AS Assignee, UserRoleData.Role " & _
"FROM QPTActions INNER JOIN UserRoleData ON UserRoleData.[Resource Name]=Replace(QPTActions.[Assigned To],',','') " & _
"WHERE DateValue(QPTActions.[Entry Date])<=DateValue('" & weekStart & "') And DateValue(QPTActions.[Close Date])>DateValue('" & weekStart & "') AND UserRoleData.Role='" & RoleName & "' " & _
"UNION SELECT [Issue ID], Replace(BarcelonaInternalActions.[Assign To],',','') AS Assignee, UserRoleData.Role " & _
"FROM BarcelonaInternalActions INNER JOIN UserRoleData ON UserRoleData.[Resource Name]=Replace(BarcelonaInternalActions.[Assign To],',','') " & _
"WHERE DateValue(BarcelonaInternalActions.[Entry Date])<=DateValue('" & weekStart & "') And DateValue(BarcelonaInternalActions.[Close Date])>DateValue('" & weekStart & "') AND UserRoleData.Role='" & RoleName & "' " & _
"UNION " & _
"SELECT [Issue ID], Replace(RDActions.[Assigned To],',','') AS Assignee, UserRoleData.Role " & _
"FROM RDActions INNER JOIN UserRoleData ON UserRoleData.[Resource Name]=Replace(RDActions.[Assigned To],',','') " & _
"WHERE DateValue(RDActions.[Entry Date])<=DateValue('" & weekStart & "') And DateValue(RDActions.[Close Date])>DateValue('" & weekStart & "') AND UserRoleData.Role='" & RoleName & "' " & _
"UNION SELECT [Issue ID], Replace(TokyoInternalActions.[Assigned To],',','') AS Assignee, UserRoleData.Role " & _
"FROM TokyoInternalActions INNER JOIN UserRoleData ON UserRoleData.[Resource Name]=Replace(TokyoInternalActions.[Assigned To],',','') " & _
"WHERE DateValue(TokyoInternalActions.[Entry Date])<=DateValue('" & weekStart & "') And DateValue(TokyoInternalActions.[Close Date])>DateValue('" & weekStart & "') AND UserRoleData.Role='" & RoleName & "';"
'open the recordset of all the data from SQL statement
etmCombinedRecordSet.Open mySQL2, , adOpenStatic
'get the record count
etmCombinedRecordSetCount = etmCombinedRecordSet.RecordCount
'*************************************************
'REPEAT CODE END
'**************************************************
'*************************************************
'REPEAT CODE BEGIN
'EUM
'**************************************************
eumRecordSet.ActiveConnection = myConnection 'set recordset var
'set name of role from array
RoleName = RoleArray(2, 0)
'get the number of Assigned Actions for a given week, for EUM
mySQL = "SELECT DISTINCT (Replace(QPTActions.[Assigned To],',','')) AS Assignee, UserRoleData.Role " & _
"FROM QPTActions INNER JOIN UserRoleData ON UserRoleData.[Resource Name]=Replace(QPTActions.[Assigned To],',','') " & _
"WHERE DateValue(QPTActions.[Entry Date])<=DateValue('" & weekStart & "') And DateValue(QPTActions.[Close Date])>DateValue('" & weekStart & "') AND UserRoleData.Role='" & RoleName & "' " & _
"UNION SELECT DISTINCT (Replace(BarcelonaInternalActions.[Assign To],',','')) AS Assignee, UserRoleData.Role " & _
"FROM BarcelonaInternalActions INNER JOIN UserRoleData ON UserRoleData.[Resource Name]=Replace(BarcelonaInternalActions.[Assign To],',','') " & _
"WHERE DateValue(BarcelonaInternalActions.[Entry Date])<=DateValue('" & weekStart & "') And DateValue(BarcelonaInternalActions.[Close Date])>DateValue('" & weekStart & "') AND UserRoleData.Role='" & RoleName & "' " & _
"UNION " & _
"SELECT DISTINCT (Replace(RDActions.[Assigned To],',','')) AS Assignee, UserRoleData.Role " & _
"FROM RDActions INNER JOIN UserRoleData ON UserRoleData.[Resource Name]=Replace(RDActions.[Assigned To],',','') " & _
"WHERE DateValue(RDActions.[Entry Date])<=DateValue('" & weekStart & "') And DateValue(RDActions.[Close Date])>DateValue('" & weekStart & "') AND UserRoleData.Role='" & RoleName & "' " & _
"UNION SELECT DISTINCT (Replace(TokyoInternalActions.[Assigned To],',','')) AS Assignee, UserRoleData.Role " & _
"FROM TokyoInternalActions INNER JOIN UserRoleData ON UserRoleData.[Resource Name]=Replace(TokyoInternalActions.[Assigned To],',','') " & _
"WHERE DateValue(TokyoInternalActions.[Entry Date])<=DateValue('" & weekStart & "') And DateValue(TokyoInternalActions.[Close Date])>DateValue('" & weekStart & "') AND UserRoleData.Role='" & RoleName & "';"
'open the recordset of all the data from SQL statement
eumRecordSet.Open mySQL, , adOpenStatic
'get the record count
eumRecordSetCount = eumRecordSet.RecordCount
'set connection for second query
eumCombinedRecordSet.ActiveConnection = myConnection 'set recordset var
'get the number of Assigned Actions for a given week, for EUM
mySQL2 = "SELECT [Issue ID], Replace(QPTActions.[Assigned To],',','') AS Assignee, UserRoleData.Role " & _
"FROM QPTActions INNER JOIN UserRoleData ON UserRoleData.[Resource Name]=Replace(QPTActions.[Assigned To],',','') " & _
"WHERE DateValue(QPTActions.[Entry Date])<=DateValue('" & weekStart & "') And DateValue(QPTActions.[Close Date])>DateValue('" & weekStart & "') AND UserRoleData.Role='" & RoleName & "' " & _
"UNION SELECT [Issue ID], Replace(BarcelonaInternalActions.[Assign To],',','') AS Assignee, UserRoleData.Role " & _
"FROM BarcelonaInternalActions INNER JOIN UserRoleData ON UserRoleData.[Resource Name]=Replace(BarcelonaInternalActions.[Assign To],',','') " & _
"WHERE DateValue(BarcelonaInternalActions.[Entry Date])<=DateValue('" & weekStart & "') And DateValue(BarcelonaInternalActions.[Close Date])>DateValue('" & weekStart & "') AND UserRoleData.Role='" & RoleName & "' " & _
"UNION " & _
"SELECT [Issue ID], Replace(RDActions.[Assigned To],',','') AS Assignee, UserRoleData.Role " & _
"FROM RDActions INNER JOIN UserRoleData ON UserRoleData.[Resource Name]=Replace(RDActions.[Assigned To],',','') " & _
"WHERE DateValue(RDActions.[Entry Date])<=DateValue('" & weekStart & "') And DateValue(RDActions.[Close Date])>DateValue('" & weekStart & "') AND UserRoleData.Role='" & RoleName & "' " & _
"UNION SELECT [Issue ID], Replace(TokyoInternalActions.[Assigned To],',','') AS Assignee, UserRoleData.Role " & _
"FROM TokyoInternalActions INNER JOIN UserRoleData ON UserRoleData.[Resource Name]=Replace(TokyoInternalActions.[Assigned To],',','') " & _
"WHERE DateValue(TokyoInternalActions.[Entry Date])<=DateValue('" & weekStart & "') And DateValue(TokyoInternalActions.[Close Date])>DateValue('" & weekStart & "') AND UserRoleData.Role='" & RoleName & "';"
'open the recordset of all the data from SQL statement
eumCombinedRecordSet.Open mySQL2, , adOpenStatic
'get the record count
eumCombinedRecordSetCount = eumCombinedRecordSet.RecordCount
'*************************************************
'REPEAT CODE END
'**************************************************
etc......
etmRecordSet.Close
etmCombinedRecordSet.Close
Set etmRecordSet = Nothing
Set etmCombinedRecordSet = Nothing
eumRecordSet.Close
eumCombinedRecordSet.Close
Set eumRecordSet = Nothing
Set eumCombinedRecordSet = Nothing
etc....