Results 1 to 16 of 16

Thread: Search!!!

  1. #1

    Thread Starter
    PowerPoster Beacon's Avatar
    Join Date
    Jan 2001
    Location
    Pub Floor
    Posts
    3,188

    Wink

    Ok again sorry for putting it here!!

    Now this piece of code searches a database and returns a result in msgboxes!
    Problem is it stops as soon as it has found 1 result. If there are 2 or more results it won't display them!

    Can someone add to this and tell me how i can get it to continue searching for other results then display them all at the end?

    cheers

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    Add to what? Where's your code?
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Just taking a stab, since there is no code to go along with it, you may be using the find function, so just use a loop eof = true. After it finds whatever your searching for, dump it in an array or whatever you want, and start the search from where it left off. You may have to use a bookmark.

  4. #4

    Thread Starter
    PowerPoster Beacon's Avatar
    Join Date
    Jan 2001
    Location
    Pub Floor
    Posts
    3,188
    Dont mind me off in my own little dream world!!

    Here we go!! Sorry

    Private Sub Command2_Click()
    Dim res1 As String
    Dim res2 As String
    Dim res3 As String

    Set rs = db.OpenRecordset("SELECT * FROM mail")
    NameQuery = InputBox("Enter A Date To Search For", "Date Query")


    rs.MoveFirst
    Do Until rs.EOF

    If rs.Fields("Date") Like "*" & LCase(NameQuery) & "*" Then
    res1 = rs.Fields("Date")
    res2 = rs.Fields("Addressee")
    res3 = rs.Fields("Description")

    MsgBox res1
    MsgBox res2
    MsgBox res3



    Exit Sub
    Else
    rs.MoveNext
    End If


    Loop
    End Sub

  5. #5
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Sydney Australia
    Posts
    804
    Changes to make are bolded.

    Private Sub Command2_Click()
    Dim res1 As String
    Dim res2 As String
    Dim res3 As String

    Set rs = db.OpenRecordset("SELECT * FROM mail")
    NameQuery = InputBox("Enter A Date To Search For", "Date Query")


    rs.MoveFirst
    Do Until rs.EOF

    If rs.Fields("Date") Like "*" & LCase(NameQuery) & "*" Then
    res1 = rs.Fields("Date")
    res2 = rs.Fields("Addressee")
    res3 = rs.Fields("Description")

    MsgBox res1
    MsgBox res2
    MsgBox res3



    Exit Sub ' remove this line
    end if
    rs.MoveNext
    End If


    Loop
    End Sub

  6. #6

    Thread Starter
    PowerPoster Beacon's Avatar
    Join Date
    Jan 2001
    Location
    Pub Floor
    Posts
    3,188

    ta ppl

    Cheers
    Actually only needed to remove "Exit Sub" and add another rs.movenext!

    Cheers once again

  7. #7
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Sydney Australia
    Posts
    804
    Why an extra rs.movenext? By putting the rs.movenext after the end if, you make a second rs.movenext statement redundant.

  8. #8

    Thread Starter
    PowerPoster Beacon's Avatar
    Join Date
    Jan 2001
    Location
    Pub Floor
    Posts
    3,188
    it works so hey!!

  9. #9
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Sydney Australia
    Posts
    804
    I guess so.

  10. #10
    Fanatic Member ExtremePimpness's Avatar
    Join Date
    Jan 2001
    Location
    Indianapolis, Indana - USA
    Posts
    550
    Originally posted by Beacon
    Dim res1 As String
    Dim res2 As String
    Dim res3 As String
    this can be shortened to Dim res1,res2,res3 as string

    Just a helpful hint

    Regards
    E.P.

  11. #11
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Extreme Pimpness, your code declared only the last variable as a string, while the others are declared as variants...just a helpful hint..

  12. #12
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Sydney Australia
    Posts
    804
    E.P, I don't think so.

    Dim res1,res2,res3 as string: will declare res1 and res2 as variants and res3 as a string.

  13. #13
    Fanatic Member ExtremePimpness's Avatar
    Join Date
    Jan 2001
    Location
    Indianapolis, Indana - USA
    Posts
    550
    i am sorry it is early or late i can't tell the differance anymore but the point was you can ommit the other two dim statements

  14. #14
    PowerPoster Lethal's Avatar
    Join Date
    Oct 2000
    Location
    Ohio
    Posts
    2,496
    Hey james, 2 great minds think alike eh.....

  15. #15
    Fanatic Member
    Join Date
    Nov 2000
    Location
    Sydney Australia
    Posts
    804
    Yep, I hate variants, they chew up my resources hungry little bastards.

  16. #16
    Hyperactive Member
    Join Date
    Mar 2001
    Posts
    485
    Originally posted by Beacon
    Dont mind me off in my own little dream world!!

    Here we go!! Sorry


    Code:
    Private Sub Command2_Click()
      Dim res1 As String
    <snipped>
    
      Do Until rs.EOF
        If rs.Fields("Date") Like "*" & LCase(NameQuery) & "*" Then
          res1 = rs.Fields("Date")
    <snipped>
          MsgBox res1
    <snipped>
    
          Exit Sub 'Remove
          Else 'Remove
          rs.MoveNext 'Remove
        End If
        rs.MoveNext 'Add this line
      Loop
    End Sub
    ExtremePimpness, so early you are into .NET already

    Anyway, it just help reduce some time for conversion when porting the code over to .NET in the future.....hehe. Variant? Let it be now, as it will no longer be....

    Harddisk

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