Results 1 to 6 of 6
  1. #1
    wojosh6 is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Dec 2015
    Posts
    8

    Creating a Form Button to Clear Table Data

    Can someone please help me with the code that will enable me to clear all of the data within a table (leaving the column headers) by clicking a form button. I'm ok with setting up the button, just need the code now.

    Thanks!
    Josh

  2. #2
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    CurrentDb.Execute "DELETE * FROM TableName"
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  3. #3
    wojosh6 is offline Novice
    Windows 10 Access 2010 64bit
    Join Date
    Dec 2015
    Posts
    8
    Hey Paul - thanks for the quick reply. I'm using the code below & the Table opens, but the data doesn't delete. Any idea what I'm doing wrong?



    Private Sub ClearElementTables_Click()


    'Clear Element Tables


    DoCmd.SetWarnings False


    CurrentDb.Execute "DELETE * FROM Comm_Loan_Data"


    DoCmd.SetWarnings True
    End Sub

    Thanks!
    Josh

  4. #4
    pbaldy's Avatar
    pbaldy is online now Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,521
    That shouldn't open the table, just delete all its records. Is the table already open?
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    June7's Avatar
    June7 is online now VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,930
    SetWarnings not needed with Execute method.

    The * wildcard is also not need but should not hurt. Fields do not need to be referenced because the entire record is deleted.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  6. #6
    DrGUI is offline Novice
    Windows 7 32bit Access 2013
    Join Date
    Aug 2015
    Location
    Parts Unknown
    Posts
    23
    Try:

    CurrentDb.Execute "DELETE FROM Comm_Loan_Data"

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

Similar Threads

  1. Replies: 5
    Last Post: 01-24-2015, 11:49 AM
  2. Replies: 1
    Last Post: 07-01-2014, 01:41 PM
  3. Replies: 2
    Last Post: 03-12-2014, 01:31 AM
  4. Replies: 2
    Last Post: 08-03-2013, 03:41 PM
  5. Command button code to clear form
    By windwardmi in forum Forms
    Replies: 15
    Last Post: 11-21-2010, 03:21 PM

Tags for this Thread

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