Using code to use content of unbound textbox control in an SQL statement to generate an adodb.recordset that will be used as the rowsource/recordset (?undecided which is preferred?) for the subform. I know that the SQL is correct because if I use the immediate window results from the debug.print in a query the correct records (and there are many) are returned but I receive the EOF, BOF true or record deleted message and the number of records (nr) comes back as 0 (I have it show up in the txttest control for ease on the form). Why oh why is this happening? I just cannot figure it out!!!! (PS I am aware of the FindAsUType function but I am sticking with this code until I find out [bold]WHY[/bold] I am experiencing this problem...otherwise I won't know what to do if it happens in a different context.)
Code:
Private Sub txtFindProduct_KeyUp(KeyCode As Integer, Shift As Integer)
Dim strProduct As String
Dim strsearch As String
Dim strtest As String
Dim rsIL As ADODB.Recordset 'item list recordset
Dim nr As Integer
Dim rsarray
Dim strSQL As String
Me.Refresh 'refresh the form
Me!txtFindProduct.SelStart = Me!txtFindProduct.SelLength 'move cursor to end of the selection
strsearch = Chr(34) & "*" & Me!txtFindProduct & "*" & Chr(34) 'incorporating the wildcards and quotes into the string
'SQL that will feed into the rsIL
strSQL = "SELECT tblProducts.ItemDescription,tblProducts.Category, tblCategories.Category" _
& " FROM tblCategories INNER JOIN tblProducts ON tblCategories.CatID = tblProducts.Category" _
& " WHERE tblProducts.Itemdescription like " & strsearch & ""
'Debug.Print strSQL
Set rsIL = New ADODB.Recordset 'set an instance of the recordset
rsIL.Open strSQL, CurrentProject.Connection, adOpenDynamic, adLockOptimistic 'open the recordset
'Debug.Print strSQL
'if there are rows, count them.
If Not rsIL.EOF Then
rsarray = rsIL.GetRows() 'takes you to end of rows
nr = UBound(rsarray, 2) + 1 'code to count the records in the array
End If
Me!txttest = nr
Set Me![subfrmProductList].Form.Recordset = rsIL
End Sub [IMG]http://www.accessforums.net/images/misc/progress.gif[/IMG]