VB Error message "The Password is incorrect"?

A

Armey

I have a protected word template that I have created with several
formfields. I have written the VBA code as well and it all meets with
my user requirements. The problem is that when I protect the word
template "Tools, Protect Document" with the editing restrictions set to
"Filling in Forms" I get the Visual Basic Error of "The Password is
incorrect" when I exit my first drop-down formfield exit macro event.
If I turn off the document password protection, everything works fine,
but I really need to protect my template so users wont make
unauthorized changes. Also, if i use the protect Form option and dont
set a password as described above, everything works fine. Any ideas
from anyone? Your thoughts are appreciated.

I am using the .Unprotect call as listed in my example below. I am not
sure if the way I am calling this if this is the problem?

MyDropDown()

With ActiveDocument
..Unprotect

---my code here---

..Protect wdAllowOnlyFormFields, NoReset
End With

End Sub

Armey
 
G

Graham Mayor

You are not passing the password to the macro?

ActiveDocument.Unprotect Password:="password"
**********
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:="password"

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
A

Armey

Graham, thank you! This worked great. I was wondering if I could put
the password in a module and reference it instead of putting the
password several times in my sub-routines?

I created a new module (module 1) and declared a public constant for my
password:

Public Const pw As String = "mypwstring"


Then in my VBA sub-routine I tried to reference the pw via the module
as follows:

Sub mySub()
With ActiveDocument
..Unprotect pw
......
.....
..Protect wdAllowOnlyFormFields, NoReset:=True, Password:=pw
End With
End Sub

I get error messages. What am I doing wrong when referencing the
password constant that I set up?

Thanks
 
J

Jonathan West

Armey said:
Graham, thank you! This worked great. I was wondering if I could put
the password in a module and reference it instead of putting the
password several times in my sub-routines?

I created a new module (module 1) and declared a public constant for my
password:

Public Const pw As String = "mypwstring"


Then in my VBA sub-routine I tried to reference the pw via the module
as follows:

Sub mySub()
With ActiveDocument
.Unprotect pw
.....
....
.Protect wdAllowOnlyFormFields, NoReset:=True, Password:=pw
End With
End Sub

I get error messages. What am I doing wrong when referencing the
password constant that I set up?

I think your problem has nothing to do with the password. You are mixing
names and unnamed arguments in the same command. Don't. Either make them all
named or all unnamed. I generally prefer to make them all named except
perhaps for very simple, very commonly-used functions where I can easily
remember what the arguments are.

..Unprotect Password:=pw
....
..Protect Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=pw
 

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