Solved

delete queries in access

Posted on 2014-10-07
6
172 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
  • 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
Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

 

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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Suggested Solutions

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 retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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 …

821 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