Results 1 to 3 of 3

Thread: Help with Search code Please(RESOLVED)

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2004
    Location
    Tampa, Fl
    Posts
    39

    Help with Search code Please(RESOLVED)

    I want to display the results in a text box.
    If I do a search by Title it will work, but searching
    by Author it says it's not there ( same book)

    VB Code:
    1. Option Explicit
    2. Private cn As ADODB.Connection
    3. Private rs As ADODB.Recordset
    4.  
    5. Private Sub cmdSearch_Click()
    6.  If Trim(txtAuthor.Text) <> "" Then
    7.   'we have something in the text box
    8.      rs.Open "SELECT * FROM ACT WHERE AUTHOR Like '" & Trim(txtAuthor.Text) & "'", cn, adOpenKeyset, adLockBatchOptimistic, adCmdText
    9.    If rs.EOF Then
    10.     'nothing was returned
    11.     lblNo.Caption = "No"
    12.    Else
    13.     'We have one or more results
    14.      With rs
    15.      txtTitle.Text = .Fields("TITLE")
    16.     End With
    17.   End If
    18. End If
    19. rs.Close
    20. End Sub

    Can anyone see what I am doing wrong?
    Thanks
    Last edited by mhipate; Apr 21st, 2004 at 07:45 PM.

  2. #2
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    I added [vbcode][/vbcode] tags around your code to make it easier to read. You should do that each time you post code.

    I don't know what the problem is but at most you will get only one title since you are not looping through the returned rs.

  3. #3
    Hyperactive Member D12Bit's Avatar
    Join Date
    Oct 2000
    Location
    Guatemala
    Posts
    373
    Try this:
    VB Code:
    1. Option Explicit
    2. Private cn As ADODB.Connection
    3. Private rs As ADODB.Recordset
    4.  
    5. Private Sub cmdSearch_Click()
    6.     If Trim(txtAuthor.Text) <> "" Then
    7.         'we have something in the text box
    8.         rs.Open "SELECT * FROM ACT WHERE AUTHOR Like '%" & Trim(txtAuthor.Text) & "%'", cn, adOpenKeyset, adLockBatchOptimistic, adCmdText
    9.     'Note the use of % ...Could be that the author name is in between of another chars...
    10.         If rs.EOF Then
    11.             'nothing was returned
    12.             lblNo.Caption = "No"
    13.         Else
    14.             'We have one or more results
    15.             txtTitle.Text = rs.Fields("TITLE") 'The use of With rs is effective with more replacements.
    16.         End If
    17.     End If
    18.     rs.Close
    19. End Sub
    "Who Dares Wins" - "Quien se Arriesga Gana"
    Mail me at:

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width