Results 1 to 8 of 8
  1. #1
    lawdy is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    172

    How to delete a record in a form?

    The next paragraph has more info. The short of it is "How do I delete a record in form view"? I have the form open and I need to delete that record.



    From my 'invoice form', I push a button which adds a new invoice with nothing but the next invoice number on it. Then I add the date and a 'proposal number'. From the proposal number, it looks up the info and completely fills in the invoice form (and table). Now, if the proposal number does not exist in the proposal table or it is determined that the job has allready be billed, I need to cancell this invoice. That is the problem. With code, I can delete the record in the invoice table. Then it displays #Deleted in all the fields. If I blank out the fields on the forms, it will not let me move off that record due to a key vialation.

  2. #2
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows Vista Access 2003
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    This is because you allready add the invoice number.
    In that case access makes a new record.
    When you delete the data in that record rather then deleting the record itself. I will notice you that the data has been removed from the fields (hence the "deleted" notification")

    The solution is that when you dont find any data from the proposal number you just let the data in the form and then delete that (near empty) record programaticly upon exiting the form.
    I do the same with one of my applications. The code checks that certain fields are empty. If so, it deletes that record.

  3. #3
    lawdy is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    172
    Ok, how do I delete that near empty record?

  4. #4
    Missinglinq's Avatar
    Missinglinq is offline VIP
    Windows 7 64bit Access 2007
    Join Date
    May 2012
    Location
    Richmond (Virginia, not North Yorkshire!)
    Posts
    3,018
    To get rid of the #Deleted just Requery the Form, using

    Me.Requery

    Linq ;0)>
    The problem with making anything foolproof...is that fools are so darn ingenious!

    All posts/responses based on Access 2003/2007

  5. #5
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows Vista Access 2010 32bit
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    Yes that is a solution to that problem, but to get rid of records that are not soppose to be there use the code below.

    First select your forms propperties (little square left top of the forms screen) and right click it.
    Now select "on exit" en select "event procedure" from the drop down menu.

    Paste this code (adjust the names of the fields and table to your data)

    Code:
    If Me.Dirty Then
    Me.Dirty = False
    End If
    
    DoCmd.SetWarnings False
    
    Dim strSQL As String
    strSQL = "DELETE * FROM YourTableHere WHERE (((YourTableHere.YourControlName) Is Null))"
    DoCmd.RunSQL strSQL
    What this does is : delete all records that meet there where criteria.
    In my case i have a parking management system, and without the license plate number i consider it no record. Thus when my database closes it deletes all records that have no licenseplate numers in my table.

    Off couse the users of my database cannot complete the permit without this data. So i know that any record deleted is actually no record at all, just empty space.
    But there are circumstances that users still manage to get a "blanc" record in. To ensure clean data i made the above code.

    Maybe your problem is solved with missinglinq's code, but if it isnt, try mine

  6. #6
    lawdy is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    172
    There is no query.

  7. #7
    lawdy is offline Competent Performer
    Windows XP Access 2010 32bit
    Join Date
    Jan 2013
    Posts
    172
    That code worked very well. Thank you.

  8. #8
    JeroenMioch's Avatar
    JeroenMioch is offline Competent Performer
    Windows Vista Access 2010 32bit
    Join Date
    May 2012
    Location
    Den Haag, Netherlands
    Posts
    368
    Your very welcome.
    Good luck with your database

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 3
    Last Post: 10-19-2012, 04:30 PM
  2. Replies: 7
    Last Post: 07-14-2012, 01:02 AM
  3. Delete continuous form record
    By tylerg11 in forum Forms
    Replies: 3
    Last Post: 03-09-2012, 03:00 PM
  4. VBA delete current record continuous form
    By tylerg11 in forum Forms
    Replies: 3
    Last Post: 02-17-2012, 12:57 PM
  5. Replies: 1
    Last Post: 11-21-2011, 07:52 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums