Filling a list box with WHERE clause
I am tring to fill a list box and was initally successfull until I put a WHERE clause in the SQL statement. Now when I try and run it I get an error that says:
"Either BOF or EOF is true, or the current record has been deleted. Requested Operation requires a current record.
I have verified that the variable, "sAuditor", is finding a match in the database. Here is my code.
///////////////////////////////////////////////////////////////////
Public Sub FillListAuditor()
Dim rst As ADODB.Recordset
Dim strList As String
Dim strSQL As String
Set m_cnn = CurrentProject.Connection
sAuditor = cmbAuditor.Value
strSQL = "SELECT RecordNumber, DateRecorded, RepName, AuditType, Auditor, AuditDate FROM Main " _
& "INNER JOIN Reps ON Main.Rep = Reps.RepId WHERE Auditor = ' " & sAuditor & " ' ORDER BY DateRecorded DESC"
Set rst = New ADODB.Recordset
rst.Open strSQL, m_cnn, adOpenForwardOnly, adLockOptimistic, adCmdText
strList = BuildStringAuditor(rst)
Me.RecList.RowSource = strList
rst.Close
End Sub
Private Function BuildStringAuditor(rst As ADODB.Recordset) As String
Dim strReturn As String
Dim varItems As Variant
Dim x As Integer
Dim y As Integer
rst.MoveFirst
varItems = rst.GetRows()
For x = LBound(varItems, 2) To UBound(varItems, 2)
For y = LBound(varItems, 1) To UBound(varItems, 1)
strReturn = strReturn & varItems(y, x) & ";"
Next y
Next x
BuildStringAuditor = strReturn
End Function
/////////////////////////////////////
Any help would be appreciated.
Thanks,
Scott
__________________
ScottP
|