Big Picture: I am trying to open 2 recordsets and test the results against a set of rules prior to loading data into my database. I have created this as a Sub attached to a command button on a form in my Access 2007 database.
Problem: My Recordsets are not opening. I am receiving a recordcount of -1 and a "Object Required" error when trying to verify the recordset loaded correctly. When I copy to SQL Statement to a query the query loads 1 and 2 records (which is the correct results) so, I know I am missing something but I am not sure what.
Problem: My Recordsets are not opening. I am receiving a recordcount of -1 and a "Object Required" error when trying to verify the recordset loaded correctly. When I copy to SQL Statement to a query the query loads 1 and 2 records (which is the correct results) so, I know I am missing something but I am not sure what.
Code:
'Create Recordset
Dim rs As ADODB.Recordset
Dim sSQL As String
Dim rs1 As ADODB.Recordset
Dim sSQL1 As String
Dim sPID As String
Dim sStat As String
Dim stErr As String
Dim lngRcdCnt As Long
sPID = [Forms]![frm_Employee]![PersonID] ' this is pulling correct value
sStat = [Forms]![frm_Employee]![StatusID] ' this is pulling Correct Value
stErr = ""
Set rs1 = New ADODB.Recordset
sSQL1 = "SELECT Max(t_AllP_Position.PosnEfftDate) AS MaxPosnEfftDate " _
& "FROM t_AllP_Position " _
& "HAVING t_AllP_Position.PersonID= " & sPID & " AND " _
& "t_AllP_Position.StatusID= " & sStat
Debug.Print sSQL1
rs1.Open sSQL1, CurrentProject.Connection, adOpenDynamic, adLockBatchOptimistic
rs1.MoveLast
Debug.Print rs1.RecordCount
Set rs = New ADODB.Recordset
sSQL = "SELECT t_AllP_StatusHistory!PersonID, t_AllP_StatusHistory!StatusID, " _
& "t_AllP_StatusHistory!RoleStatus, t_AllP_StatusHistory!Status_End, " _
& "t_AllP_Position!PosnEfftDate, t_AllP_Position!PosnCurrent " _
& "FROM t_AllP_StatusHistory INNER JOIN t_AllP_Position ON t_AllP_StatusHistory.StatusID = t_AllP_Position.StatusID " _
& "AND t_AllP_StatusHistory.PersonID = t_AllP_Position.PersonID " _
& "WHERE t_AllP_StatusHistory.PersonID = " & sPID _
& " AND t_AllP_StatusHistory.StatusID= " & sStat & " AND t_AllP_Position.PosnCurrent= Yes"
Debug.Print sSQL
rs.Open sSQL, CurrentProject.Connection, adOpenDynamic, adLockBatchOptimistic
rs.MoveLast
Debug.Print rs.RecordCount
'Verify the Recordset loaded with 1 and only 1 record
If rs.BOF And re.EOF Then
MsgBox "Problem with Recordset used to verify data prior to loading qualifications. " & vbCrLf _
& "Document the Person's Name, PersonID, and StausID and let the System Administrator know you received this message." _
, vbCritical + vbOKOnly, "Recordset Record Count = 0"
Exit Sub
End If
Comment