Solved

delete queries in access

Posted on 2014-10-07
6
176 Views
Last Modified: 2014-10-12
I want to delete queries in my db that have any of the names but not the word "column", will this work?

For Each Qry In Db.QueryDefs


Select Case Qry.Name
 
Case InStr(Qry.Name, "abi") <> 0 And InStr(Qry.Name, "column") > 0
DoCmd.DeleteObject acQuery, Qry.Name

Case InStr(Qry.Name, "cap") <> 0 And InStr(Qry.Name, "column") > 0
DoCmd.DeleteObject acQuery, Qry.Name

Case InStr(Qry.Name, "glass") <> 0 And InStr(Qry.Name, "column") > 0
DoCmd.DeleteObject acQuery, Qry.Name

Case InStr(Qry.Name, "kee") <> 0 And InStr(Qry.Name, "column") > 0
DoCmd.DeleteObject acQuery, Qry.Name

Case InStr(Qry.Name, "smmt") <> 0 And InStr(Qry.Name, "column") > 0
DoCmd.DeleteObject acQuery, Qry.Name



End Select

 
 
 
 
 
Next

Open in new window


if not how please
0
Comment
Question by:PeterBaileyUk
[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
  • 2
6 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40366619
do you mean, if the name of the query is "qry_whatever_column" which have the word "column" in the name, delete the query?


For Each Qry In Db.QueryDefs
    if InStr(Qry.Name, "column") > 0 then
          DoCmd.DeleteObject acQuery, Qry.Name
   end if
next
0
 

Author Comment

by:PeterBaileyUk
ID: 40366633
the queries are like this which can be deleted
QryGlass3Series

Qry[clientname][model]

BUT

I must preserve queries like so "columnout" is keyword
QryABIColumnOut

the five client names are
abi
glass
kee
cap
smmt
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 40366646
clear as  mud!

What is  "columnout" is keyword?
0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Author Comment

by:PeterBaileyUk
ID: 40366666
its a word in the queries I dont want to delete only five of them

QryAbiColumnOut
QryCapColumnOut
QryKeeColumnOut
QrySMMTColumnOut
QryGlassColumnOut

The rest I want to delete are of the form

Qry[clientname]xxx ie abi cap etc as above 5 client names butthe xxx part does not have columnout
0
 

Accepted Solution

by:
PeterBaileyUk earned 0 total points
ID: 40366685
ok did it myself

For Each Qry In Db.QueryDefs



 
If InStr(Qry.Name, "abi") <> 0 And InStr(Qry.Name, "column") = 0 Then
DoCmd.DeleteObject acQuery, Qry.Name

End If

If InStr(Qry.Name, "cap") <> 0 And InStr(Qry.Name, "column") = 0 Then
DoCmd.DeleteObject acQuery, Qry.Name
End If
If InStr(Qry.Name, "glass") <> 0 And InStr(Qry.Name, "column") = 0 Then
DoCmd.DeleteObject acQuery, Qry.Name
End If
If InStr(Qry.Name, "kee") <> 0 And InStr(Qry.Name, "column") = 0 Then
DoCmd.DeleteObject acQuery, Qry.Name
End If
If InStr(Qry.Name, "smmt") <> 0 And InStr(Qry.Name, "column") = 0 Then
DoCmd.DeleteObject acQuery, Qry.Name

End If
0
 

Author Closing Comment

by:PeterBaileyUk
ID: 40375444
because I found the solution myself
0

Featured Post

Independent Software Vendors: 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!

Question has a verified solution.

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

Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
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.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

724 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