Results 1 to 5 of 5
  1. #1
    Join Date
    Oct 2002
    Location
    Charlotte, NC
    Posts
    45

    Question Unanswered: Easiest Way to Clear a Database?

    I need a form button to delete all records from a database.

    What is the easiest way to Remove All Records from the database? .. and leaves me with a fresh new database?
    -----

    "How much deeper would the ocean be without sponges?"

  2. #2
    Join Date
    Dec 2002
    Posts
    18

    Question what database?

    what database? what version of database?
    Are there relations between the tables with integrety?

  3. #3
    Join Date
    Dec 2002
    Posts
    4

    Re: Easiest Way to Clear a Database?

    Originally posted by stratego16
    I need a form button to delete all records from a database.

    What is the easiest way to Remove All Records from the database? .. and leaves me with a fresh new database?

    Assuming that you have considered referential integrity etc., and it is definitely OK to remove all records from a table, add the following code to your button on_click event:

    clear_table ("YourTableName")


    which should call the following code:

    ' Delete all records from a table

    Public Function clear_table(pstrTableName As String)

    DoCmd.SetWarnings False
    DoCmd.RunSQL "delete * from [" & pstrTableName & "]"
    DoCmd.SetWarnings True

    End Function

    This clears records from one table - repeat for each table name, or loop through non-system TableDefs calling this routine for each table.

  4. #4
    Join Date
    Oct 2002
    Location
    Charlotte, NC
    Posts
    45

    Post Update

    Thanks for the advice PoppeKop and SteveP

    I ended up just deleting the table and then recreating it with another simular generic database. But I plan on trying your suggestion SteveP. I think your suggestion of setting warning on and off will solve another of my many problems.

    Thanks again
    brian
    -----

    "How much deeper would the ocean be without sponges?"

  5. #5
    Join Date
    Dec 2002
    Posts
    4
    Glad to help. Let us know if you need any further assistance.

Posting Permissions

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