?
Solved

delete queries in access

Posted on 2014-10-07
6
Medium Priority
?
177 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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.
Traditionally, the method to display pictures in Access forms and reports is to first download them from URLs to a folder, record the path in a table and then let the form or report pull the pictures from that folder. But why not let Windows retr…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…
Suggested Courses

752 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