0

When I enter into debug mode in Access 97, the program will halt on any error, even if that error is occurring after On Error Resume Next.

I have a function that tests if an element key is in a Collection Col using

On Error Resume Next
var = Col.Item(key)  'Here the error is raised, and makes debug mode useless
...
InConnection = Not (Err.Number = 5)

This works well in production, but it makes running the program in debug mode useless.

Is there a way to avoid that the program halts on certain errors in debug mode ?

As far as I could search there is no way to test if a key exist in a collection in Access 97, other than try and catch the error using the above method.

Erik A
  • 31,639
  • 12
  • 42
  • 67
Lorenz Meyer
  • 19,166
  • 22
  • 75
  • 121
  • Generally, I loop over all items in a collection using a _For Each_ loop to test if an item exists (or use a dictionary instead). However, Access 97 is far before when I started programming. Is that not feasible for Access 97? – Erik A Nov 01 '18 at 13:54
  • @ErikvonAsmuth The `For Each` loop is possible, but this will create unnecessary nested loop and rais the time complexity to `O^2`. As for a `Dictionary` it does not seem to exist in Access 97. – Lorenz Meyer Nov 01 '18 at 14:03
  • 2
    `Dictionary` is a COM object (e.g. `Set dict = CreateObject("Scripting.Dictionary")`.) . While looping does increase time complexity, I usually consider avoiding it premature optimization, looping over small collections generally doesn't take more than a couple of milliseconds, and avoiding it is messy since we don't have try...catch so it requires you to restate how you're handling errors. – Erik A Nov 01 '18 at 14:10

1 Answers1

1

In VBA editor Tools | Options... on tab General activate Break on Unhandled Errors in Error Trapping group to silence OERN sections.

To check key existence in a VBA.Collection w/o error trapping one would need a specially crafted typelib, like the one discussed in this forum thread.

Moreover, such typelib is a prerequisite for practicing the art of writing VBA code with Break on All Errors set -- a small feat in itself :-))

wqw
  • 11,771
  • 1
  • 33
  • 41