Results 1 to 5 of 5

Thread: Code problem

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2000
    Posts
    33

    Unhappy

    whats wrong with this code???

    Set rs = Db.OpenRecordset("SELECT * FROM MyNames")
    With rs Do
    strFind = "Name='Bjorn'"
    rs.FindFirst strFind
    If Not .NoMatch Then
    i = i + 1
    Do Until .NoMatch
    rs.FindNext strFind
    i = i + 1
    Debug.Print .Name & ", " & i & " records found!"
    Loop
    Else
    MsgBox "No name found"
    End If
    Loop

    if i have 2 names that are the same and if i search at the name that are 2 times in my database how can i get that 2 persons ore more

  2. #2
    Lively Member Surgeon's Avatar
    Join Date
    Oct 2000
    Posts
    121

    Wink

    Why don't you use this one, I think it's a bit more simple :

    Dim strFind As String
    Dim rs As Recordset
    strFind = "bjorn"
    Set rs = Db.OpenRecordset("SELECT * FROM MyNames WHERE (Name=""" & strFind & """);")
    If rs.BOF And rs.EOF _
    Then
    Beep
    MsgBox "No name found"
    Else
    rs.MoveLast
    rs.MoveFirst
    Beep
    MsgBox "A number of " & rs.RecordCount & " records were found"
    End If
    rs.Close

  3. #3
    Fanatic Member Stevie's Avatar
    Join Date
    Mar 2000
    Location
    London, UK
    Posts
    565
    Try this ...

    Code:
    strFind = "bjorn"
    
    strSQL = "SELECT COUNT(*) AS TotalCount " & _
             "FROM MyNames " & _
             "WHERE Name = '" & strFind & "'"
    
    Set rs = db.OpenRecordset(strSQL)
    
    MsgBox "Records Found : " & rs!TotalCount
    
    rs.Close
    Set rs = Nothing
    VB6 sp5, SQL Server 2000, C#

    There are no stupid questions. Only stupid people.

  4. #4

    Thread Starter
    Member
    Join Date
    Nov 2000
    Posts
    33

    Question Yes but i want to out but the names from it

    like if i have to bjorn in my database i wanne output it on a textbox for example thats all

  5. #5
    Fanatic Member
    Join Date
    Oct 2000
    Location
    London
    Posts
    1,008
    Bjorn,

    Your original code looks OK except you have one Do and two Loops, one With and no End With.

    Replace the last 'Loop' with 'End With'.

    Are you sure it compiles?

    P.
    Not nearly so tired now...

    Haven't been around much so be gentle...

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