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

    Record deletion (Access 2003)

    I have a subform which has the command DoCmd.GoToRecord , , acNewRec on a button. It then allows the user to fill in a form. However the code in a button to abort the new record does not seem to work as a blank record gets left in the table. The code used is :

    If Me.Dirty = True Then
    DoCmd.SetWarnings False
    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
    DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
    DoCmd.SetWarnings True
    End If

    I have stepped through the code and it passes through the code as being dirty.

    UPDATE

    I have added textboxes on the subform showing the mainforms primary key and the subforms primary key. When I add a new record and before filling any fields, the primary key of form/table 1 shows the correct number 334 and the subform textbox shows the word (autonumber). When I fill in a field, that changes to 16321, when I abort the record and look in the table it shows a blank record with primary key of 334 but the other one is 16322? The two tables are related in a one to many relationship.

    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: Record deletion (Access 2003)

    I have noticed that if I add a new record in the subform, the primary key shown in the textbox gets allocated an autonumber.

    But if after typing in data I press the abort button just having the code :

    DoCmd.SetWarnings False
    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
    DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70
    DoCmd.SetWarnings True

    Then the autonumber increments a new number, so when I hide the subform (subform never gets closed just hidden) and now see the mainform and exit the program the table gets a blank record in it. How can I overcome this? Regards

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

    Re: Record deletion (Access 2003)

    Problems sorted. There was a control on the form that had an on exit event which went into a function and around in a circle to cause the problem. Regards

  4. #4
    Super Moderator
    Join Date
    Jun 2002
    Location
    Mt Macedon, Victoria, Australia
    Posts
    3,993
    Thanks
    1
    Thanked 45 Times in 44 Posts

    Re: Record deletion (Access 2003)

    Glad you sorted it.

    By the way

    DoCmd.DoMenuItem acFormBar, acEditMenu, 8, , acMenuVer70
    DoCmd.DoMenuItem acFormBar, acEditMenu, 6, , acMenuVer70

    which is the code created by the Access wizard, is archaic code for:

    DoCmd.RunCommand acCmdDeleteRecord
    Regards
    John



Posting Permissions

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