ADO - how to abort an AddNew?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    ADO - how to abort an AddNew?

    Hi all.

    I'm currently on my first adventure in ADO programming, using VB6 against an Access 2000 database. It's coming along pretty well, but I've hit a snag. Using DAO, I sometimes hit a situation where I issued an AddNew command, then changed my mind. If I remember correctly (it has been a while) I was able to abort the AddNew by reissuing the same command again. (Same applied to Edit, I believe.)

    Is there a way to do that using ADO? I've been reading up on the AddNew command, but I'm finding it a little confusing. I think I still have quite a bit of studying to do before I really understand ADO.
  • Killer42
    Recognized Expert Expert
    • Oct 2006
    • 8429

    #2
    Never mind, from the doco it looks as though the .CancelUpdate method is what I need.

    Comment

    • ADezii
      Recognized Expert Expert
      • Apr 2006
      • 8834

      #3
      Originally posted by Killer42
      Hi all.

      I'm currently on my first adventure in ADO programming, using VB6 against an Access 2000 database. It's coming along pretty well, but I've hit a snag. Using DAO, I sometimes hit a situation where I issued an AddNew command, then changed my mind. If I remember correctly (it has been a while) I was able to abort the AddNew by reissuing the same command again. (Same applied to Edit, I believe.)

      Is there a way to do that using ADO? I've been reading up on the AddNew command, but I'm finding it a little confusing. I think I still have quite a bit of studying to do before I really understand ADO.
      [CODE=vb]
      Dim MyRS As ADODB.Recordset , intResponse As Integer
      Set MyRS = New ADODB.Recordset

      With MyRS
      .Source = "tblName"
      .ActiveConnecti on = CurrentProject. Connection
      .CursorType = adOpenKeyset
      .LockType = adLockOptimisti c
      .Open
      End With

      MyRS.AddNew
      MyRS![TheName] = "Joe Schmoe"
      intResponse = MsgBox("Cancel Record Addition?", vbQuestion + vbYesNo, "Record Addition")
      If intResponse = vbYes Then
      MsgBox "Record not added to Table", vbExclamation, "Record Addition Cancelled"
      MyRS.CancelUpda te
      Exit Sub
      Else
      'do nothing - add Record
      End If
      MyRS.Update

      MyRS.Close[/CODE]
      NOTE: If you invoke the AddNew Method in DAO, and do not issue a subsequent Update Method, the new Record will NOT be added to the Table and there will be no warning related to this action. I think the reverse is True in ADO. Just another bit of useless information which I occasionally provide. (lol).

      Comment

      Working...