Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB How-To
|
VB How-To Ask your "How do I do this with VB?" questions in this forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 30th, 2005, 05:18 AM
Registered User
 
Join Date: Nov 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to check if query's are present in a database

I'm making a form that deletes certain query's. But I don't know how to check if the query's are present in the databases because I'm gonna use this form in different databases.

I'm trying to do this:
DoCmd.DeleteObject acQuery, "name"

This works of course but if i run the form again it gives an error because the query isn't present any more. What code do i use to check if the query is present and if so, then do the above deleteobject command?

I'm new to VB so I'm sorry if this is a very noobish question. But I looked on the forum and couldn't find the answer I need.

btw:
I'm using Visual Basic in Microsoft Access.
 
Old November 30th, 2005, 08:46 AM
Authorized User
 
Join Date: Nov 2005
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Learn about EXISTS Clause, it might help u to fine whether any queries exists in database or not? if not, u need not to go for DELETE operation..




                                            ~~Dev~~
 
Old December 2nd, 2005, 07:19 AM
Registered User
 
Join Date: Nov 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Some guy came up with this and it works.
----------------------------------------------------------
Function VindQuery(Naam As String) As Boolean

  Dim Db As dao.database
  Dim QueryDefinitie As QueryDef

  Set Db = CurrentDb

  For Each QueryDefinitie In Db.QueryDefs
    If QueryDefinitie.Name = Naam Then VindQuery = True
  Next
End Function
------------------------------------------------------------


 
Old December 3rd, 2005, 01:43 AM
Authorized User
 
Join Date: Nov 2005
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hey,

 Could u tell me how "VindQuery" is working and where we have to use this function..

~ ~ ~ There is no Right, There is no Wrong, KNOWLEDGE is Only the POWER ~ ~ ~
 
Old December 9th, 2005, 10:07 AM
Registered User
 
Join Date: Nov 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well it's for checking if a query is in the database. The Boolean either gives a true or false signal. When true, do this. When false, do that.

I needed it to see if a query was there, and if so delete it.



 
Old December 9th, 2005, 02:27 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 627
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by rmsmit
 Some guy came up with this and it works.
----------------------------------------------------------
Function VindQuery(Naam As String) As Boolean

Dim Db As dao.database
Dim QueryDefinitie As QueryDef

Set Db = CurrentDb

For Each QueryDefinitie In Db.QueryDefs
    If QueryDefinitie.Name = Naam Then VindQuery = True
Next
End Function
------------------------------------------------------------
it should have been
----------------------------------------------------------
If QueryDefinitie.Name = Naam Then
   VindQuery = True
   exit for
endif
----------------------------------------------------------
because there is no need to continue the loop if the query is found.
But it is much faster to do:

----------------------------------------------------------
Function QueryExists(Naam As String) As Boolean
  on error resume next
  QueryExists = not (CurrentDb.QueryDefs(Naam) is nothing)
end function
----------------------------------------------------------

Marco
 
Old December 13th, 2005, 11:48 AM
Registered User
 
Join Date: Nov 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok thx for the tip Marco.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Difference Between This Two Query's msmiran BOOK: Beginning SQL 0 September 18th, 2008 06:45 PM
Check if Object Exists in the Database Coby Access VBA 2 June 7th, 2007 02:56 PM
How to check database existence? angelran Classic ASP Databases 0 October 30th, 2005 06:39 AM
multiple check boxes to database cincinnaticj7 Classic ASP Databases 2 January 25th, 2005 03:53 PM
Dynamic check boxes writing to database..help!! cincinnaticj7 Classic ASP Databases 0 January 25th, 2005 10:47 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.