Solved

delete macro to remove data in table

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

740 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