Results 1 to 7 of 7
  1. #1
    Evgeny's Avatar
    Evgeny is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Apr 2010
    Posts
    85

    Delete record function

    Hi guys,



    I have button with OnClick function

    Private Sub Command53_Click()
    DoCmd.RunSQL "Delete Customer ID.* From Customer;"
    DoCmd.Requery
    End Sub

    Which deletes CustomerID and all related records, it works fine, but i want it just to delete current record not all of them. is it possbile?

    Many Thanks

    Evgeny

  2. #2
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    That really works? Your solution would be along the lines of

    DoCmd.RunSQL "Delete * From Customer WHERE ID = " & Me.ID

    But you may want to use the command button wizard. People often get into trouble trying to affect records with code on a form bound to the table. If the record is "dirty" on the form, the SQL delete will fail with an error along the lines of "Another user is editing ...". The "other user" is the bound form, not an actual user.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    Evgeny's Avatar
    Evgeny is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Apr 2010
    Posts
    85
    yeah, i does work and suprisingly i created the function myself lol. I tried running this

    DoCmd.RunSQL "Delete * From Customer WHERE Customer Number = " &
    Me.txt_CustomerNumber
    DoCmd.Requery

    But it gives me run-time error "3075", synax error in query expression "Customer Number ="

  4. #4
    Evgeny's Avatar
    Evgeny is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Apr 2010
    Posts
    85
    DoCmd.RunSQL "Delete * From Customer Where [Customer Number] = " & Me.txt_CustomerNumber ... Simple brakets around Customer Number solved the problem

  5. #5
    Evgeny's Avatar
    Evgeny is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Apr 2010
    Posts
    85
    If you have a min can you look in to my Combo Box post please.

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,530
    Spaces in object names are a never-ending source of aggravation. I'd get rid of them if it's not too late.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    Evgeny's Avatar
    Evgeny is offline Advanced Beginner
    Windows XP Access 2007
    Join Date
    Apr 2010
    Posts
    85
    haha, thank you for advise. Gona Backup my DB and GO Ahad and Delete these bad boys, wish me luck

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

Similar Threads

  1. Delete record if duplicate
    By rubintheyid in forum Access
    Replies: 8
    Last Post: 03-30-2010, 11:33 AM
  2. Delete record harder than it seems
    By turbo910 in forum Forms
    Replies: 5
    Last Post: 12-09-2009, 04:05 PM
  3. Delete erroneous record(s)
    By jgelpi in forum Programming
    Replies: 4
    Last Post: 07-10-2009, 07:08 AM
  4. Two Delete Record Problems
    By skyrise in forum Programming
    Replies: 1
    Last Post: 04-22-2009, 09:37 PM
  5. Delete a record
    By f.crocco in forum Programming
    Replies: 1
    Last Post: 10-08-2007, 07:28 AM

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