Determine if a query exists

I

Ian Shaw

Hi Guys,

I need help in determining if a query exists alraedy in a database window??

What is the code to do that??

Any assistance greatly appreciated!!

Cheers

Ian
 
G

Graham R Seach

Ian,

Dim strQueryName As String
On Error Resume Next
strQueryName = CurrentDb.QueryDefs("qryMyQuery").Name
If (Err <> 0) Then 'Query doesn't exist

But I have to ask, what are you really trying to do?

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 
I

Ian Shaw

I am trying to use some code as a catchall for when someone first opens a
database and they want to utilise a query that I have developed for the first
time and then whilst they have the databse open they want to use the same
query again.
Ian If else type statement.

Is that the best way to go??

My options?
 
I

Ian Shaw

Thanksvery much to Graham and Stuart!!

At the moment I am getting an error when I inserted your code:

"Item Not Found in this collection"

Also the "CurrentDb.QueryDefs("str").name" (is in lower case as shown)
What am I doin wrong?

Cheers Graham and Stuart
Thanks guys I know I am a dumbaclumpin!!
 
S

Stuart McCall

Ian Shaw said:
Thanksvery much to Graham and Stuart!!

At the moment I am getting an error when I inserted your code:

"Item Not Found in this collection"

Also the "CurrentDb.QueryDefs("str").name" (is in lower case as shown)
What am I doin wrong?

Cheers Graham and Stuart
Thanks guys I know I am a dumbaclumpin!!

Set a reference to 'Microsoft DAO 3.6' in order to use the Data Access
Objects library. If there is already a reference to 'Microsoft Activex Data
Objects' and you're not using ADO then remove it.
 
G

Graham R Seach

Wel, I don't know which code you used, but if you used mine then that's the
correct error. But you shouldn't actually be seeing the error because the
'On Error Resume Next' statement should prevent the error being raise to the
UI. Make sure the 'On Error Resume Next' statement is in the position as
shown in my original code segment.

Change "str" to the name of the query whose existence is in question.

I don't understand what you meat by "Ian If else type statement".

Regards,
Graham R Seach
Microsoft Access MVP
Sydney, Australia
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top