473,396 Members | 1,714 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Determine if query "x" exists

Hello all,

I have (hopefully) an easy question for you all. I'm running Access '03 and have created a pile of VBA code to create a form and some queries related to each control in the form. (Basically, it uses structured naming conventions to create a form with a bunch of combo boxes that allow the user to easily add and remove controls... anyway--)

I am using the statement

Expand|Select|Wrap|Line Numbers
  1. With CurrentDb
  2. .QueryDefs.Delete ("qryName")
  3. Set qrydef = .CreateQueryDef("qryName", strSQL)
  4. .Close
  5. End With
to delete existing queries and make new ones, however my code returns an error message when the query doesn't exist when it tries to delete it.

Is there a function that can tell me if a query with a specific name exists that I can use in an "If" statement? Ideally, it would be something like:

Expand|Select|Wrap|Line Numbers
  1. If qryExists("qryName") Then
  2. .QueryDefs.Delete("qryName")
  3. End If
Any help would be greatly appreciated!

Thanks!
Jan 30 '08 #1
3 31779
ADezii
8,834 Expert 8TB
Hello all,

I have (hopefully) an easy question for you all. I'm running Access '03 and have created a pile of VBA code to create a form and some queries related to each control in the form. (Basically, it uses structured naming conventions to create a form with a bunch of combo boxes that allow the user to easily add and remove controls... anyway--)

I am using the statement

Expand|Select|Wrap|Line Numbers
  1. With CurrentDb
  2. .QueryDefs.Delete ("qryName")
  3. Set qrydef = .CreateQueryDef("qryName", strSQL)
  4. .Close
  5. End With
to delete existing queries and make new ones, however my code returns an error message when the query doesn't exist when it tries to delete it.

Is there a function that can tell me if a query with a specific name exists that I can use in an "If" statement? Ideally, it would be something like:

Expand|Select|Wrap|Line Numbers
  1. If qryExists("qryName") Then
  2. .QueryDefs.Delete("qryName")
  3. End If
Any help would be greatly appreciated!

Thanks!
Expand|Select|Wrap|Line Numbers
  1. Dim qdf As DAO.QueryDef
  2.  
  3. For Each qdf In CurrentDb.QueryDefs
  4.   If qdf.Name = "qryName" Then
  5.     CurrentDb.QueryDefs.Delete "qryName"
  6.      Exit For
  7.   End If
  8. Next
Jan 31 '08 #2
Expand|Select|Wrap|Line Numbers
  1. Dim qdf As DAO.QueryDef
  2.  
  3. For Each qdf In CurrentDb.QueryDefs
  4.   If qdf.Name = "qryName" Then
  5.     CurrentDb.QueryDefs.Delete "qryName"
  6.      Exit For
  7.   End If
  8. Next

Works like a charm! Thanks Adezii.
Jan 31 '08 #3
ADezii
8,834 Expert 8TB
Works like a charm! Thanks Adezii.
You are quite welcome.
Jan 31 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

43
by: steve | last post by:
I am quite frustrated with php’s include, as I have spent a ton of time on it already... anyone can tell me why it was designed like this (or something I don’t get)? The path in include is...
2
by: steve | last post by:
Hi, I need to do conditional script "include", but like to pull the code from db instead of a file. How do I do that? Reason: I like to implement some complex regex logic, and make it table...
3
by: Shapper | last post by:
Hello, How to determine if a Session Variable exists? In Page_Load I need to check is Session("MyVar") Exists. If it doesn't exist then I created it and give it a value: Session("myVar") =...
8
by: Ulysse | last post by:
Hello, I need to clean the string like this : string = """ bonne mentalit&eacute; mec!:) \n <br>bon pour info moi je suis un serial posteur arceleur dictateur ^^* \n ...
2
by: Angus | last post by:
I am trying to change the selection in Javascript - but this HTML element is not a standard option control. On the web page it looks like a dropdown list - and you click on the right hand down...
5
by: Maria Sudderman | last post by:
I have a prblem with the "onClick" command. onClick="insert('<a href="URI">', '</a>')"> but this is not correct! why? Maria
1
by: manchin2 | last post by:
Hi, Can anybody please provide the information about "&quot" and its use, if possible please provide an example. ...
4
by: thaytu888888 | last post by:
Here is my codes in aspx page: <td colspan="2" class="main_menu" runat="server" onclick='toggleDisplay(<%#Eval("description")%>);'><%#Eval("description")%></td> Here is in "View source": ...
2
by: jmash | last post by:
Suppose I have the following string whch is part of an xml string: String s= "Script Id=&quot;Test&quot; " And I need to get s= "Script Id="Test" " Can anyone tell me how this can acheived? ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.