Results 1 to 6 of 6
  1. #1
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Deletion Problem (MSACCESS 2003)

    I have an abort entering a new record button, however I cannot seem to catch the record from being saved. I thought the code below would work but it fails.

    If TCMODE = 1 Or TCMODE = 2 Then
    If Me.Dirty = True Then

    DoCmd.SetWarnings False
    DoCmd.RunCommand acCmdDeleteRecord
    DoCmd.SetWarnings True
    Else

    If Me.NewRecord = True Then

    DoCmd.SetWarnings False
    DoCmd.RunCommand acCmdDeleteRecord
    DoCmd.SetWarnings True

    End If
    End If
    End If

    Any ideas, thanks

  2. #2
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Deletion Problem (MSACCESS 2003)

    I have changed my newrecord to false, and it now covers a new record being aborted where no fields were filled, and if fields were filled.

    If Me.NewRecord = False Then

    DoCmd.SetWarnings False
    DoCmd.RunCommand acCmdDeleteRecord
    DoCmd.SetWarnings True

    End If

    I cannot understand why the delete function works when newrecord is false. I stepped through in debug and it dows pass through the latter code. Maybe someone can explain to me why a newrecord being false needs to be deleted. Thanks

  3. #3
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Deletion Problem (MSACCESS 2003)

    Could you try to explain what you mean more clearly? I find your description very confusing. <img src=/S/scratch.gif border=0 alt=scratch width=25 height=29>

  4. #4
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Deletion Problem (MSACCESS 2003)

    Thanks Hans. I have a form where there is a create new record button. Sometimes during the data entry of this form data never gets entered, and the user terminates the record (but does not close form, as it has other sections on the same form), and somtimes the user enters data but cancels entry, during which time he may have use options on the form that cause the focus to go elsewhere. So I am trying to establish whether (when aborting a new record entry) the record needs deleting, undoing etc. I was using both the dirty function and the Newrecord function. But my main question is:

    If a Me.Newrecord=False, then why should it need deleting? Logically, I would have thought it would require Me.Newrecord to be true to need deleting if not wanted. Thanks

  5. #5
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Deletion Problem (MSACCESS 2003)

    If Me.NewRecord is True, the active record has never been saved yet. This means that you can't delete it, because there is no (saved) record yet to be deleted. You can undo the record to get rid of it.

    If Me.NewRecord is False, the active record has been saved at least once, although not necessarily since the most recent changes. If you want to discard the changes since the last time the record was saved, you can use Me.Undo, but if you want to remove the record altogether, you have to delete it. This will get rid of the saved record.

  6. #6
    4 Star Lounger
    Join Date
    Feb 2008
    Location
    United Kingdom
    Posts
    490
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Deletion Problem (MSACCESS 2003)

    Thanks Hans. That clears up my understanding, best regards

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •