Connecting Tech Pros Worldwide Forums | Help | Site Map

please help :) "on error resume next" does not work!

Newbie
 
Join Date: Jul 2006
Posts: 3
#1: Jul 14 '06
Hello guys, I stumbled upon this forum recently and am hoping someone here can help me with this problem.

This is probably very stupid, but I can't get past this easy problem / glitch.

All I need to do is test if a table exists, and then delete it if it does (so I can create a new one).

Of course, you can't delete a table if it doesn't exist, and this returns an error.

Every source I've looked at says an easy way to solve this is by using the on error resume next statement. to skip the error.

my code looks like this (simplified)

Quote:
Private Sub Command0_Click()

On Error Resume Next
DoCmd.DeleteObject acTable, "testtable"

End Sub
this doesn't return an error if "testtable" exists, but always returns the error if "testtable" does not exist.

to me it seems like I have a glitch in VBA somewhere. Anyone have any suggestions?

Thanks!
(microsoft access 2000)



Familiar Sight
 
Join Date: Jun 2006
Location: Edmonton, AB
Posts: 179
#2: Jul 14 '06

re: please help :) "on error resume next" does not work!


Try this code instead (assuming, of course, that this is for the OnClick event of a button with the name "DeleteTestTable"):

On Error GoTo Err_DeleteTestTable_Click

DoCmd.DeleteObject acTable, "testtable"

Exit_DeleteTestTable_Click:
Exit Sub

Err_DeleteTestTable_Click:
MsgBox Err.Description
Resume Exit_DeleteTestTable_Click

Good Luck.
comteck
Newbie
 
Join Date: Jul 2006
Posts: 3
#3: Jul 14 '06

re: please help :) "on error resume next" does not work!


Thanks Comteck for your reply.

That code looks interesting, I see what you're trying to do there.

Unfortunately, though I belive your code is good (as is mine), I get the same error.

The error I get here (access specific because it can't find the table) is the following:

Quote:
Run Time Error '7874'
Microsoft Access cant find the object 'testtable'
I should mention that "on error resume next" does not work in any level, public or private functions, or in module functions that I've tried.

I am wondering if something is hosed on my version of access, or i need to add another library? The debugger highlights the command (blue) appropriately, but the "Object Browser" is not able to find me any combination of the "on error resume next" wording in the command reference.

I have the following libraries enabled:
Visual Basic for applications
Microsoft Access 9.0 object library
OLE Automation
Microsoft active x data objects 2.1 library

I can't see that a command as basic as "on error resume next" wouldn't be included in the visual basic for applications libary..but i wanted to throw it out there
Newbie
 
Join Date: Jul 2006
Posts: 3
#4: Jul 14 '06

re: please help :) "on error resume next" does not work!


OK>>> I FOUND the solution

IMO..the problem and solution to this is extremely microsoft'd up.

Under Tools>Options>General you must set the error trapping to "Break on Unhandled Errors". I had it to "break on all errors". Evidently, "on error resume next" doesn't override the "break on all errors" setting..... DAHHHHH

Anyway, there's the solution for the archives..... I'm suprised it was so hard to find this solution and that it took until now for me to figure it out, but i guess that's the way it goes. I hate to think of the hours I spent chasing this stupid problem
Newbie
 
Join Date: Aug 2006
Posts: 1
#5: Aug 9 '06

re: please help :) "on error resume next" does not work!


thanx man you are my lifesaver!! very kind of you to post this solution. it works!! thou one has to restart VB 6...
Newbie
 
Join Date: Aug 2006
Posts: 2
#6: Aug 14 '06

re: please help :) "on error resume next" does not work!


Thank you so much for posting this. It solved my problem too!

It took me a while, though: I first looked in Access (for Tools-->Options-->General). The option is actually in the visual basic editor (in Tools-->Options--General). :cool:

Thanks again.
Newbie
 
Join Date: Nov 2006
Posts: 1
#7: Nov 16 '06

re: please help :) "on error resume next" does not work!


Hi guys
Thank you for posting this solution.
I think Microsoft have changed this in an update or Service Pack because I had code that was working six months ago.
Regards
Stephen
NeoPa's Avatar
Administrator
 
Join Date: Oct 2006
Location: London - UK
Posts: 15,722
#8: Nov 16 '06

re: please help :) "on error resume next" does not work!


I had a colleague ask about this just earlier today.
In the VBA window, look at Tools \ Options \ General \ Error Trapping.
If you have it set to Break on All Errors, then the Error Trapping will never work.
Sorry to take so long to reply - I've been too busy.
I could have saved you the aggro :(.

Quote:

Originally Posted by Help

Error Trapping

Determines how errors are handled in the Visual Basic development environment. Setting this option affects all instances of Visual Basic started after you change the setting.

Break on All Errors — Any error causes the project to enter break mode, whether or not an error handler is active and whether or not the code is in a class module.


Break in Class Module — Any unhandled error produced in a class module causes the project to enter break mode at the line of code in the class module which produced the error.


Break on Unhandled Errors — If an error handler is active, the error is trapped without entering break mode. If there is no active error handler, the error causes the project to enter break mode. An unhandled error in a class module, however, causes the project to enter break mode on the line of code that invoked the offending procedure of the class.

Newbie
 
Join Date: Aug 2007
Posts: 1
#9: Aug 20 '07

re: please help :) "on error resume next" does not work!


Thank you so much for posting this reply. I've been stumbling around, trying to resolve this error for a week.

- JC
Newbie
 
Join Date: Sep 2007
Posts: 2
#10: Sep 15 '07

re: please help :) "on error resume next" does not work!


Saved my life -- could have spent days looking for solution!
Thanks!
Reply