How do I get a macro to work inside of a locked form?

G

Guest

I am trying to create a form in a table format that will use a macro to
import information from Access into my document. I need the form protected
because I am using the drop down features on a couple of occasions. I also
am trying to make it very simple for my fellow co-workers to use.
I am not very familiar with macros and am using one that was created by
previous employee. The macro works, but I just can't get it to perform
inside of the locked form. I clicked on the field properties added the macro
to be inserted on start, but it won't work. What am I doing wrong?
 
G

Graham Mayor

Some functions will not work when the form is locked. You must unlock the
form in your code, do what you want then lock it again. The code to lock and
unlock is:

Dim bProtected As Boolean

'Unprotect the file
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect Password:=""
End If
'********************************
'Do your thing
'********************************

'Reprotect the document.
If bProtected = True Then
ActiveDocument.Protect _
Type:=wdAllowOnlyFormFields, NoReset:=True, Password:=""
End If

You'll need to insert the password if any at the two places shown.

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

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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