Results 1 to 5 of 5

Thread: Updating a record

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Posts
    1,384

    Updating a record

    My grid is attached to a database via ADO. I need to be able to update the information in this grid. But I keep getting the following error:

    Error -2147467259 Key column information is insufficient or incorrect. Too many rows were affected by update

    This is my code:
    Code:
    Private Sub cmdUpdate_Click()
    
    On Error GoTo err
           
        For i = 0 To adoQuoteDets.Recordset.RecordCount - 1
        With adoQuoteDets.Recordset
            .Fields("QuoteNo") = cboQuoteNo.Text
            .Fields("PartNumber") = grd.TextMatrix(i, 1)
            .Fields("Description") = grd.TextMatrix(i, 2)
            
            If IsNumeric(grd.TextMatrix(i, 3)) Then
                .Fields("Quantity") = grd.TextMatrix(i, 3)
            Else
                .Fields("Quantity") = "0"
            End If
                            
            If Not IsNumeric(grd.TextMatrix(i, 4)) Then
                .Fields("UnitPrice") = "0"
            Else
                .Fields("UnitPrice") = grd.TextMatrix(i, 4)
            End If
                            
            If Not IsNumeric(grd.TextMatrix(i, 5)) Then
                .Fields("LineTotal") = "0"
            Else
                .Fields("LineTotal") = grd.TextMatrix(i, 5)
            End If
                        
            .Update
        End With
        Next i
            
    err:
        If err.Number <> 0 Then
            MsgBox "Error " & Str(err.Number) & " " & err.Description, vbCritical + vbOKOnly
            err.Clear
        End If
        
    End Sub
    Mel

  2. #2
    zemp
    Guest
    I am assuming that you have one row in your grid for every record in your resordset. I see you looping through your grid but I don't see you looping through your recordset. You seem to be assigning everything to the same record. You probably need a movefirst and movenext statement.

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Posts
    1,384
    Hey Zemp,
    I have edited my code to include .moveFirst and .moveNext but I'm still getting the same error[Code]
    Private Sub cmdUpdate_Click()

    On Error GoTo err

    adoQuoteDets.Recordset.MoveFirst

    For i = 0 To adoQuoteDets.Recordset.RecordCount - 1
    With adoQuoteDets.Recordset
    .Fields("QuoteNo") = cboQuoteNo.Text
    .Fields("PartNumber") = grd.TextMatrix(i, 1)
    .Fields("Description") = grd.TextMatrix(i, 2)

    If IsNumeric(grd.TextMatrix(i, 3)) Then
    .Fields("Quantity") = grd.TextMatrix(i, 3)
    Else
    .Fields("Quantity") = "0"
    End If

    If Not IsNumeric(grd.TextMatrix(i, 4)) Then
    .Fields("UnitPrice") = "0"
    Else
    .Fields("UnitPrice") = grd.TextMatrix(i, 4)
    End If

    If Not IsNumeric(grd.TextMatrix(i, 5)) Then
    .Fields("LineTotal") = "0"
    Else
    .Fields("LineTotal") = grd.TextMatrix(i, 5)
    End If

    .MoveNext
    End With
    Next i

    err:
    If err.Number <> 0 Then
    MsgBox "Error " & Str(err.Number) & " " & err.Description, vbCritical + vbOKOnly
    err.Clear
    End If

    End Sub
    Mel

  4. #4

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2001
    Posts
    1,384
    Zemp, you still there?
    Mel

  5. #5
    zemp
    Guest
    Sorry for the delay, I don't stay on continually. Usually check back every couple of hours.

    Beyond that i don't know. But I found this article with a quick search on MSDN. It might help.

    http://support.microsoft.com/directo...EN-US;Q269379&

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