Solved

delete macro to remove data in table

Posted on 2013-12-04
5
369 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
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…
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…

828 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