dbTalk Databases Forums  

Delete query def

comp.databases.ms-access comp.databases.ms-access


Discuss Delete query def in the comp.databases.ms-access forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Rich P
 
Posts: n/a

Default Re: Delete query def - 05-04-2010 , 02:20 PM






try a loop in your error handler

Dim qdf as QueryDef

...

Err:
For Each qdf In dbs.Querydefs
If qdf.Name = strQDF Then
dbs.QueryDefs.Delete (strQDF)
Exit For
End if
Next
Exit Sub

Rich

*** Sent via Developersdex http://www.developersdex.com ***

Reply With Quote
  #2  
Old   
alex
 
Posts: n/a

Default Delete query def - 05-04-2010 , 02:21 PM






Delete query def

Hello,
Using Access ’03…

In my error handling, I have the following code:

Exit Sub
errHandler:
On Error Resume Next
dbs.QueryDefs.Delete (strQDF)
msgbox err.description
End Sub

What I’m trying to do, is that if my sub fails for any reason; delete
the query def(s) that may have been created before the error occurred.

Seems simple enough, but for some strange reason I’m getting a run-
time error in my error handling:’3265’ Item not found in this
collection.

I use On Error Resume Next before I delete any qdf, just in case it
does not exist--and it's always worked. I don’t understand why it
doesn’t work in error handling?

Can someone clue me in?

Thanks,
alex

Reply With Quote
  #3  
Old   
John von Colditz
 
Posts: n/a

Default Re: Delete query def - 05-04-2010 , 04:01 PM



If you haven't appended it to the querydefs collection, it's just a
temporary, so you don't have to delete it.

John

alex used his keyboard to write :
Quote:
Delete query def

Hello,
Using Access ’03…

In my error handling, I have the following code:

Exit Sub
errHandler:
On Error Resume Next
dbs.QueryDefs.Delete (strQDF)
msgbox err.description
End Sub

What I’m trying to do, is that if my sub fails for any reason; delete
the query def(s) that may have been created before the error occurred.

Seems simple enough, but for some strange reason I’m getting a run-
time error in my error handling:’3265’ Item not found in this
collection.

I use On Error Resume Next before I delete any qdf, just in case it
does not exist--and it's always worked. I don’t understand why it
doesn’t work in error handling?

Can someone clue me in?

Thanks,
alex

Reply With Quote
  #4  
Old   
alex
 
Posts: n/a

Default Re: Delete query def - 05-05-2010 , 05:56 AM



On May 4, 3:20*pm, Rich P <rpng... (AT) aol (DOT) com> wrote:
Quote:
try a loop in your error handler

Dim qdf as QueryDef

..

Err:
For Each qdf In dbs.Querydefs
* If qdf.Name = strQDF Then
* *dbs.QueryDefs.Delete (strQDF)
* *Exit For
* End if
Next
Exit Sub

Rich

*** Sent via Developersdexhttp://www.developersdex.com***
Thanks Rich; that did work.
I have two qdfs so I have to write two loops (if I had four: four
loops)! I still don't understand why the on error resume next does
not work!

Reply With Quote
  #5  
Old   
alex
 
Posts: n/a

Default Re: Delete query def - 05-05-2010 , 05:57 AM



On May 4, 5:01*pm, John von Colditz <johnv... (AT) earthlink (DOT) net> wrote:
Quote:
If you haven't appended it to the querydefs collection, it's just a
temporary, so you don't have to delete it.

John

alex used his keyboard to write :



Delete query def

Hello,
Using Access ’03…

In my error handling, I have the following code:

Exit Sub
errHandler:
* * * * * *On Error Resume Next
* * * * * *dbs.QueryDefs.Delete (strQDF)
* *msgbox err.description
End Sub

What I’m trying to do, is that if my sub fails for any reason; delete
the query def(s) that may have been created before the error occurred.

Seems simple enough, but for some strange reason I’m getting a run-
time error in my error handling:’3265’ Item not found in this
collection.

I use On Error Resume Next before I delete any qdf, just in case it
does not exist--and it's always worked. *I don’t understand why it
doesn’t work in error handling?

Can someone clue me in?

Thanks,
alex- Hide quoted text -

- Show quoted text -
John,
I thought that query defs were automatically appended. Which seems to
happen in my case. If I don't delete the qdfs, they will throw an
error the next time the user invokes the code.
alex

Reply With Quote
  #6  
Old   
Rich P
 
Posts: n/a

Default Re: Delete query def - 05-05-2010 , 10:14 AM



Quote:
Thanks Rich; that did work. I have two qdfs so I have to write two
loops (if I had four: four loops)! I still don't understand why the on
error resume next does
not work!
<

Instead of writing a bunch of loops you could also do this:

Dim QD() As String, qdf As QueryDef, i As Integer
...
Err:
i = 0
For Each qdf in dbs.QueryDefs
Redim Preserve QD(i)
QD(i) = qdf
i = i + 1
Next
For i = 0 To Ubound(QD)
dbs.Querydefs.Delete(QD(i))
Next



Rich

*** Sent via Developersdex http://www.developersdex.com ***

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.