Solved

delete macro to remove data in table

Posted on 2013-12-04
5
367 Views
Last Modified: 2013-12-04
Hi Experts (access 2003)

Need a macro to delete all the data in tbl_output based on the field "level" - so delete everyone who is not a level 1.

the fields in the table are:-
Id
first name
last name
 Parent
level
0
Comment
Question by:route217
  • 4
5 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 39695198
Try this in a query:

DELETE *
FROM YourTable
WHERE Level <> 1

Open in new window


and if you need a macro to run it, use the RunQuery action.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 39695208
<<  use the RunQuery action. >>

Sorry - the action is actually "OpenQuery".  (just use the default options with that action)
0
 

Author Comment

by:route217
ID: 39695220
Hi mbizup

sorry new to access totaly lost. ...step by step please...

I have
sub tidyup()

Docmd.setwarnings false

Docmd.setwarnings true
end sub

s far.
0
 
LVL 61

Accepted Solution

by:
mbizup earned 500 total points
ID: 39695251
That is not a macro as you'd asked for... it is VBA code :-)

To fill in the blanks in the code:


sub tidyup()

dim strSQL as string
strSQL = "DELETE * FROM tbl_output WHERE Level <> 1"

Docmd.setwarnings false
Docmd.RunSQL strSQL   
Docmd.setwarnings true
end sub

Open in new window



Or my preferred method:

sub tidyup()

dim strSQL as string
strSQL = "DELETE * FROM tbl_output WHERE Level <> 1"
currentdb.execute strSQL, dbFailOnError

end sub

Open in new window

0
 
LVL 61

Expert Comment

by:mbizup
ID: 39695277
Just as an aside.., comparing macros and vba... while a lot is possible with macros, including this particular task, VBA in the long run is the way to go.

VBA is easier to maintain and develop, gives you (the developer) more control, and provides you with meaningful error messages when things go wrong.
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…

864 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now