Error Handling in VBA in the Office Suite

J

John C

Hi,

Happy New Year to all.

Writing some code in MS Access 2003, SP2 installed on MS Windows XP Pro
(also SP2 + hotfixes)

Sub has some custom error handling which includes raising bespoke errors...

Err.raise lngMyErrNumber,,MyErrText

works only if lngMyErrNumber is <=65535 BUT the online help says that
Err.Number is of type Long.
VBA reports "Run-time Error 5: Invalid procedure call or argument" if
lngMyErrNumber is >65535

I'm obviously going out of my mind but I did check the behaviour in MS Excel
2003 (also SP2) on a different box but I still got the same behaviour...
MS reserves the error numbers up to 65535...

Negative numbers appear to work just fine... So, what have I missed? When
was a Long limited to 65535 or less?

Thanks

JC
 
T

TC

I can repro that:

err.Raise 65540,"hello"
gives rte 5, invalid procedure

? clng(65540)
65540

? clng(655400000000000000000000000000)
gives rte 6, overflow

However - the fact that a parameter is a Long, for example, does not
necessarily mean that all Long values are acceptable. For example, in
the "xyz" method, the valid values might be 1 to 40000, in which case
it would have to use a Long, but you couldn't say 40001 (for example).
So I think that your whole expectation in this, is incorrect.

I'd go back & carefully re-read the F1 help for the Raise mehod.

In addition, there is a bias constant somewhere that you can add to
your own error numbers, foi th specific purpos of keeping them seperate
to the standard errors. I thought that it was vbObjectError, or
somesuch, but I don't have Access here to check. Maybe that would help.

HTH,
TC
 
J

John C

TC,

Thanks for the reply. I have gone back an re-read the help. It's a fair
cop... society is to blame etc. :) The help is quite clear that the valid
range is 0 - 65535 for all error numbers. I obviously completely misread
that as just for MS numbers.

Thanks again
JC
 
T

TC

No probs, glad it helped. I'd have checked it myself, bu I didn't have
Access handy to do so.

HTH,
TC
 

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