Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Runtime Error '3020': Update or CancelUpdate without AddNew or Edit 1

Status
Not open for further replies.

PSchubert

Technical User
Jun 6, 2006
57
AU
I am trying to convert an mdb to VB6. I want to create a new record, assign a value to a field that is one greater than the highest existing value for that field, and open a form to the new record. Using the following code, I get the above error, and I don't know why!

Code:
Private Sub btnNew_Click(Index As Integer)

    Dim ws As Workspace
    Dim db As DAO.Database
    Dim rs As DAO.Recordset
    Dim strSQL As String
    Dim dblAccountNum As Double

    Set ws = DBEngine.Workspaces(0)
    Set db = ws.OpenDatabase("ArtWare.mdb")
    
    strSQL = "SELECT * FROM tblClients " & _
           " ORDER BY nfldAccountNum ASC;"
    
    Set rs = db.OpenRecordset(strSQL)
    
    With rs
        .MoveLast
        !nfldAccountNum = dblAccountNum
        .AddNew
        !nfldAccountNum = dblAccountNum + 1
        .Update
        .MoveLast
    End With
    
    Load frmClient
    frmClient.Show
    
    With frmClient
        .txtidxClients = rs!idxClients
    End With
    
    rs.Close
    db.Close
    ws.Close
    
    Set rs = Nothing
    Set db = Nothing
    Set ws = Nothing
    
End Sub
 
What happens when you switch !nfldAccountNum = dblAccountNum to dblAccountNum = !nfldAccountNum?

Ni neart go cur le cheile.
 
How are ya PSchubert . . .

Try the following:
Code:
[blue]  With rs
     .AddNew
     !nfldAccountNum = dblAccountNum + 1
     .Update
  End With[/blue]

See Ya! . . . . . .

Be sure to see thread181-473997 [blue]Worthy Reading![/blue] [thumbsup2]
Also faq181-2886 [blue]Worthy Reading![/blue] [thumbsup2]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top