Results 1 to 6 of 6
  1. #1
    mar_t is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    Nov 2010
    Posts
    52

    Delete Record; Yes/No


    I copy & paste this code from my previous post. The code works perfectly, however if I select No it will display this error " Run-time error "2501" The RunSQL action was canceled" and I have two option..its either End or Debug. What I want is that. once I click No the run-time error will not appear...help.

    Code:
    Private Sub cmdDelete_Click()
      sql = "DELETE FROM tblGroup WHERE GroupID = '" & GroupID & "'"
      DoCmd.RunSQL (sql)
      lst1.Requery
      End Sub

  2. #2
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    need to have a " * " in your SQL and add square brackets around GroupID

    Code:
    sql = "DELETE * FROM tblGroup WHERE [GroupID] = '" & GroupID & "';"

  3. #3
    mar_t is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    Nov 2010
    Posts
    52
    Hi jgelpi16,

    As suggested from my previous post, I'm re-posting the codes since the data type for my GroupID field is a number. However, I can't seem to make it work... run-time error 2501 still appear ...please help

    Code:
    sql = "Delete * FROM tblGroup WHERE [GroupID] = (" & Me.GroupID & ")"

  4. #4
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    Ok...You'll need to take the following code....

    Code:
    Dim vGroupID as Integer
    Dim mySQL as String
    vGroupID = objGroupID.Value
    
    mySQL = "DELETE * FROM tblGroup WHERE [GroupID] = " & vGroupID & ";"
    CurrentDb.Execute mySQL
    This code assumes "GroupID" is the field name within your table "tblGroup". "objGroupID" represents your combo box, text box, etc. that contains the GroupID you want to delete.

  5. #5
    mar_t is offline Advanced Beginner
    Windows XP Access 2002
    Join Date
    Nov 2010
    Posts
    52
    I added a couple of codes from "Delete record" wizard and its finally working.

    Thank you.

  6. #6
    jgelpi16 is offline Expert
    Windows XP Access 2010 32bit
    Join Date
    Mar 2010
    Location
    Charlotte, NC
    Posts
    544
    What was your final code?

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

Similar Threads

  1. Delete record function
    By Evgeny in forum Programming
    Replies: 6
    Last Post: 04-12-2010, 09:19 PM
  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