update problem cannot see why

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • akoymakoy
    New Member
    • Oct 2006
    • 42

    #1

    update problem cannot see why

    Is there anything wrong with my code?? Im just trimming the entries because a lot has spaces after them. after i click my button there is a runtime error saying that the update has affected too many rows.


    Code:
    Private Sub Command4_Click()
    Dim x As String
    Dim y As String
    
            Dim MyConn As ADODB.Connection
            Dim MyRecSet As ADODB.Recordset
            Set MyConn = New ADODB.Connection
            MyConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\thesis\FINAL\FilipinoDict.mdb;"
            MyConn.Open
             Set MyRecSet = New ADODB.Recordset
        
        MyRecSet.CursorLocation = adUseClient
        MyRecSet.Open "SELECT * FROM Dictionary", MyConn.ConnectionString, adOpenKeyset, adLockPessimistic
            With MyRecSet
        
            Do Until .EOF
                x = .Fields(0)
                y = .Fields(1)
         
                .Fields(0).Value = RTrim(x)
                
                .Fields(1).Value = RTrim(y)
           
                
                .MoveNext
            Loop
            End With
    End Sub
    Thanks
    Last edited by willakawill; Jan 28 '07, 07:38 PM. Reason: not using code tags
  • willakawill
    Top Contributor
    • Oct 2006
    • 1646

    #2
    Hi, you are editing without updating. By the end of your while loop you have edited every row in your recordset and updated none.
    Try it this way:
    Code:
    Dim bm As Variant
    
    Do Until MyRecSet.EOF
       bm = MyRecSet.Bookmark
       MyRecSet.Fields(0).Value = RTrim(MyRecSet.Fields(0).Value)
                
       MyRecSet.Fields(1).Value = RTrim(MyRecSet.Fields(1).Value )
       MyRecSet.Update
       MyRecSet.Bookmark = bm
                
       MyRecSet.MoveNext
    Loop

    Comment

    • Killer42
      Recognized Expert Expert
      • Oct 2006
      • 8429

      #3
      Originally posted by willakawill
      Code:
         bm = MyRecSet.Bookmark
         MyRecSet.Bookmark = bm
      I'm curious, will. What's the reason for storing and then setting the bookmark?

      Comment

      Working...