Solved

How do I clear records from an Access table using VBA?

Posted on 2008-10-25
6
1,049 Views
Last Modified: 2013-11-27
I want to clear the records in the 'LSI_US_BookOrders' table before I run the next line of code.

DoCmd.TransferText acImportDelim, "LSI_US ImportSpec", "LSI_US_BookOrders", "f:\Shared Documents\LSI_US.txt"

I can't remember.  Searched long enough. Help.
0
Comment
Question by:c9k9h
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
  • 2
6 Comments
 
LVL 18

Accepted Solution

by:
jmoss111 earned 50 total points
ID: 22805468
Hi c9k9h,

dim db as dao.database
set db = currentdb
db.execute("DELETE * FROM LSI_US_BookOrders"), dbfailonerrors

Regards,

Jim
0
 

Author Comment

by:c9k9h
ID: 22805606
Thank you Jim.  I am getting a compile error.  User-defined type not defined on the dao line.  I'm working on a remote server and 'References' is greyed out so I cannot change anything.  Is there a work around that you know of?
Thanks!
Karen
0
 
LVL 18

Expert Comment

by:jmoss111
ID: 22805625
Dim dbcur As Database
   Set dbcur = DBEngine.Workspaces(0).OpenDatabase("X:\MyPath\myRemoteDB.mdb")    
    dbcur.execute("DELETE * FROM LSI_US_BookOrders"), dbfailonerrors

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 74

Assisted Solution

by:Jeffrey Coachman
Jeffrey Coachman earned 50 total points
ID: 22805660
c9k9h

Try using SQL:
(BTW, you always want some type of confirmation before deleting *all* records! Because deleted records in Access can never be recovered)

Dim bytConfirm As Byte
bytConfirm = MsgBox("Delete all records? (deleted records cannot be recovered)", vbYesNo + vbQuestion)
    If bytConfirm = vbNo Then
        Exit Sub
    End If
   
    DoCmd.SetWarnings False
    DoCmd.RunSQL "Delete * FROM LSI_US_BookOrders "
    DoCmd.SetWarnings True
   
    MsgBox "Done deleting all from the table", vbInformation

JeffCoachman
0
 

Author Comment

by:c9k9h
ID: 22805730
Jim - still the compile error.  I've sent a note to the admin to see if I can get the access to the 'References.'  I'm sure both of you're solutions would work if it were available.

Jeff - You're absolutely right on the caution of deleting records.  I actually did have a message box.  I like your code and it works like a charm.

Thank you both - I think you both gave good posts for other readers as well.  I'm upping the points and splitting them.
0
 
LVL 74

Expert Comment

by:Jeffrey Coachman
ID: 22806215
;-)
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Did you know that more than 4 billion data records have been recorded as lost or stolen since 2013? It was a staggering number brought to our attention during last week’s ManageEngine webinar, where attendees received a comprehensive look at the ma…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question