+ Reply to Thread
Results 1 to 2 of 2

VBA help needed to deleted all records except last record from a table

  1. #1
    Forum Contributor
    Join Date
    10-30-2011
    Location
    Doha
    MS-Off Ver
    MS office 365
    Posts
    701

    VBA help needed to deleted all records except last record from a table

    Hi Folks,

    I need a VBA code to delete all records except last record from table named "Test" (Filed "E_ID" is primary key with auto number). i.e If I have set of records "E_ID" 1 to 10 then I want the code to delete all records of "E_ID" 1 to 9, just keep "E_ID" 10.


    Is it possible? please help me.

    Thanks,
    Joshi
    Cheers,

    Joshi
    Being with a winner makes you a winner

  2. #2
    Forum Guru Norie's Avatar
    Join Date
    02-02-2005
    Location
    Stirling, Scotland
    MS-Off Ver
    Microsoft Office 365
    Posts
    19,643

    Re: VBA help needed to deleted all records except last record from a table

    Try this.

    DELETE * FROM Test WHERE E_ID<>(SELECT MAX(E_ID) FROM Test)
    If posting code please use code tags, see here.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Help needed to count of records from table to user form
    By krjoshi in forum Access Programming / VBA / Macros
    Replies: 2
    Last Post: 09-04-2014, 03:08 PM
  2. Replies: 3
    Last Post: 06-03-2014, 12:29 AM
  3. [SOLVED] Recover Accidentally Deleted RECORDS of a Table in Ms-Access 2003
    By :) Sixthsense :) in forum Access Tables & Databases
    Replies: 5
    Last Post: 04-30-2014, 01:38 PM
  4. Runtime error 3021 Either BOF or EOF is true or the current record has been deleted.
    By aman1234 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 12-19-2011, 01:52 PM
  5. [SOLVED] Records got deleted
    By italia in forum Excel General
    Replies: 2
    Last Post: 06-08-2006, 12:35 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1