I am writing this search routine to find image files and display the filename in a list view. The code below to search is on frmSearch and the listview is on another form called frmMain.
The error I am getting is "wrong number of arguments or invalid property assignment" and it focuses on this:
lngCount = rs.Fields("Cat", "Title", "FileExtension", "FileName")
What am I doing wrong?
Code:Private Sub cmdSearch_Click() Dim conn As ADODB.Connection Set conn = New ADODB.Connection Dim rs As ADODB.Recordset Set rs = New ADODB.Recordset Dim sql As String Dim res As String Dim lngCount As Long Dim lngItem As Long prgBar.Visible = True prgBar.Min = 0 prgBar.Max = 10 prgBar.Value = 10 sql = "SELECT * FROM Master WHERE Master.Title = '" & txtTitle.Text & "' and Master.Cat = '" & txtCat.Text & "' and Master.FileExtension = '" & txtFE.Text & "' and Master.FileName = '" & txtIFN.Text & "'" conn.ConnectionString = "Provider=Microsoft.JET.OLEDB.4.0;Data Source=" & App.Path & "\dbGraphics.mdb;Persist Security Info=False" conn.CursorLocation = adUseClient conn.Open rs.Open sql, conn, adOpenStatic, adLockOptimistic lngCount = rs.Fields("Cat", "Title", "FileExtension", "FileName") If rs.EOF Then MsgBox "No files found for the search criteria.", vbOKOnly, "Search Results" Else For lngItem = 1 To lngCount 'Adds the item to the list frmMain.lvwResults.ListItems.Add , , rs!Cat 'Adds the ListSubItem of the first item added frmMain.lvwResults.ListItems(lngItem).ListSubItems.Add , , rs!Title Next End If rs.Close conn.Close Set rs = Nothing Set conn = Nothing End Sub




Reply With Quote