Solved

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

Posted on 2008-10-25
6
1,041 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
Industry Leaders: 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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Access developers frequently have requirements to interact with Excel (import from or output to) in their applications.  You might be able to accomplish this with the TransferSpreadsheet and OutputTo methods, but in this series of articles I will di…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…

756 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