Error handling: Err.Number is always 0

B

Beeawwb

Hi everybody,

Tidying up my code today and I realise that my error trapping is no longer
working. I previously realised that when using oDoc.Unprotect, if the
password was incorrect I would get error 5485. So I put in code to trap this.

If Err.Number = 5485 Then
Dim ErrorMsg
Logfile.Output "Document protected by password."
ErrorMsg = MsgBox("This document contains a password. Please unprotect
manually before use.", vbCritical, "Password Detected")
Else: MsgBox (Err.Number & " - " & Err.Description)
End If

The problem is, I've just tested this with a password protected document,
and sure enough, an error occurs when doing oDoc.Unprotect, however it gives
Err.Number as 0. When I turn off the error handling (On Error goto
ErrorCatch) I correctly get a Microsoft Visual Basic error, "Run-time error
'5485': The password is incorrect"; End; Debug; Help.

So the error is clearly the right one, just the Err object is not holding
the Number correctly. I notice in my Locals window, that there is no "Err"
object. I thought Err was a global that always existed. Or do I have to
explicitly define it?

Thanks for your help,

-Bob
 
B

Beeawwb

Oops, here I thought my PC had crashed an not posted my original thread
(which didn't show up when I logged back in.) Looks like it did and now I
have a duplicate topic. I've solved this problem in the original topic
thread, my apologies for the wasted post.

-Bob
 

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