Opening passworded document

stevo

Registered User.
Local time
Today, 19:52
Joined
Feb 16, 2010
Messages
10
I have an access database with an action button on a form. This button is hyperlinked to a word document.

I would like to encrypt this document; does anyone know the code I could use to give the password to open the document using VB from within the database. Hope this makes sense - thanks.
 
You can't use a hyperlink with that (as far as I know), but you can do it this way:
Code:
Function OpenDoc(strDocNameAndPath As String, strPassword As String)
    Dim objWord As Object
    Dim wdDoc As Object
 
    Set objWord = CreateObject("Word.Application")
 
    objWord.Visible = True
 
    Set wdDoc = objWord.Documents.Open(strDocNameAndPath, PasswordDocument:=strPassword )
 
 
    wdDoc.UserControl = True
 
    Set wdDoc = Nothing
End Function

Paste that function into a STANDARD module and then save it with a name that isn't the same as the function.

And then you call it like this:

Call OpenDoc("C:\Temp\MyDoc.doc", "MyPwdHere")
 
Thanks very much BOB for a your concise and helpful reply.
 
Just a bit of a concern. There are programs that can open MS Office applications that have a password. Only a few days ago, I had a problem with an Access db that was supposed to be password-protected. I was able to retrieve the password and open the db. The same my apply to Word.
 
Hi John
This is not code for finding an unknown password. It consists of opening a passworded document with a known password.

It is for the database users to be able to open passworded documents that no one can alter.

I have also included in my code Readonly: = True so that the database users arn't able to edit the documents
 
Stevo, thanks for your comment.

My comment was general in nature about passworded MS Office applications. Just in case the content of the Word doc is very sensitive, there is a good chance that it can be opened and read by other means.

John
 
Thanks John, but if someone was able to open these documents it would only be an inconvenience not a big issue.
 

Users who are viewing this thread

Back
Top Bottom