giving a Word doc passwords from Access VBA

P

pvp

I am sitting in Access VBA and create a Word doc. I want
it to have passwords for read and write whenever it is
opened. This code I thought would do it:

"
Sub createDoc(client As String)
' create a new Word doc

Dim docDoc As Object
Dim docApp As Object
Dim junk As Integer

'create a new Word app and doc
' assume no existing app

Set docApp = CreateObject("Word.Application")
Set docDoc = docApp.Documents.Add
' add title line
docApp.Selection.Font.name = "Comic Sans MS"
docApp.Selection.Font.Bold = True
docApp.Selection.Font.Size = 24
docApp.Selection.typetext "Counselling notes for
Client " & client & vbCrLf & vbCrLf
'prepare for ordinary text in the file
docApp.Selection.Font.name = "Times New Roman"
docApp.Selection.Font.Bold = False
docApp.Selection.Font.Size = 13
'and copy in the initial comments on the client as
HeaderFooter is first described to the system

docApp.Selection.typetext "___________________________" &
vbCrLf
docApp.Selection.typetext "General Comment:" & vbCrLf
docApp.Selection.typetext "First seen on " & Format
(Now, "MMMM dd, yyyy at hh:mm AM/PM") & vbCrLf
docApp.Selection.typetext Forms![clients].[dealt
with] & vbCrLf & vbCrLf

'save doc contents
docDoc.SaveAs "C:\program files\counselog\counselog
docs\" & Forms!switchboard!thisUser & "\" & client
& ".doc"

' set passwords - same for read and write
docDoc.password = DLookup("[password
readwrite]", "[my details]")
docDoc.WritePassword = DLookup("[password
readwrite]", "[my details]")

docDoc.Close 0 'wdDoNotSaveChanges = 0
Set docApp = Nothing

End Sub
"

But when my Access prog runs this code, it appears to go
OK but when later I try to open the Word doc from Word
itself, it does not ask for passwords!

Any suggestions? I must be missing something...

Many thanks.
 

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