Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

delete macro to remove data in table

Posted on 2013-12-04
5
Medium Priority
?
374 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
[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
  • 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
The Windows Phone Theme Colours is a tight, powerful, and well balanced palette. This tiny Access application makes it a snap to select and pick a value. And it doubles as an intro to implementing WithEvents, one of Access' hidden gems.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

715 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