Results 1 to 5 of 5

Thread: Delete A Record

  1. #1
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Louisville, Kentucky, USA
    Posts
    605
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Delete A Record

    Good Morning Everyone,

    I was hoping someone would tell me what the correct code is for deleting a record.

    I have a temp table that will only be holding information of 1 record. On the OnOpen Event of a form, I want to set code to delete the one record.

    Thanks all....
    Roberta Price <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

  2. #2
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Indiana, USA
    Posts
    107
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Delete A Record

    Roberta, I use a lot of temp tables to hold one record of data for a Word mail merge. The temp tables are filled by a make table query. The query always overwrites the one record. Do your tables append a record to the temp table? If so, a make table query would resolve that problem. HTH

  3. #3
    Silver Lounger
    Join Date
    Jan 2001
    Location
    Indianapolis, Indiana, USA
    Posts
    1,862
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Delete A Record

    Hi Roberta,

    You can use SQL code to delete the record. It would be something like:
    <pre>Dim dbs as Database
    Set dbs = CurrentDB()
    dbs.Execute "DELETE * FROM tblTemp"
    Set dbs = Nothing</pre>


    I often struggle with SQL code. The easiest way I've found to get the SQL is to set up a Query with the grid interface then switch to SQL view and copy the SQL code.

    Hope this helps....

  4. #4
    3 Star Lounger
    Join Date
    Jan 2001
    Location
    The Netherlands
    Posts
    216
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Delete A Record

    Mark and Roberta,

    One small addition to the code of Mark:

    Dim dbs as Database
    Set dbs = CurrentDB()
    dbs.Execute "DELETE * FROM tblTemp", dbFailOnError
    Set dbs = Nothing

    If you leave the dbFailOnError switch you will not get any message if the SQL statement is not correct!

  5. #5
    5 Star Lounger
    Join Date
    Feb 2001
    Location
    Louisville, Kentucky, USA
    Posts
    605
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Delete A Record

    Thanks all...really do appreciate it...both solutions will work fine....I don't know why I didn't think about the mtq..after all I use them all the time.


    At any rate thanks to all who replied.
    Roberta Price <img src=/S/cheers.gif border=0 alt=cheers width=30 height=16>

Posting Permissions

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