Solved

delete queries in access

Posted on 2014-10-07
6
165 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 119

Expert Comment

by:Rey Obrero
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 119

Expert Comment

by:Rey Obrero
ID: 40366646
clear as  mud!

What is  "columnout" is keyword?
0
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now