From: alex on
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
From: Rich P on
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 ***
From: John von Colditz on
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


From: alex on
On May 4, 3:20 pm, Rich P <rpng...(a)aol.com> wrote:
> 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!
From: alex on
On May 4, 5:01 pm, John von Colditz <johnv...(a)earthlink.net> wrote:
> 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