Password to Word template

C

css

I'm using the following code to open & print a document in Word 2003:

'opens word
Set wordApp = New Word.Application
wordApp.Visible = False 'don't show word, just print
'opens template
Set wordDoc = wordApp.Documents.Add(Template:="Template.dot")
'prints document
wordApp.Options.PrintBackground = False
wordApp.ActiveDocument.PrintOut
'closes document
wordDoc.Close (False)
'closes word
wordApp.Quit

When a user runs this from a button on a form, they are prompted 2 times to
enter the password.

How can I pass their password to Word so that it won't prompt them again?

Connie
 
C

Clifford Bass

Hi Connie,

Try this (all one line):

Set wordDoc = wordApp.Documents.Open("Template.dot", , , , ,
"TemplatePassword")

Clifford Bass
 
C

css

Clifford:

Thanks for the help; it get's me one step closer, but still not working. The
template itself does not have a password; the data does, which is in a table
in the database the code is coming from.

When I copy & paste your code, I substituted my document name, but I don't
know what to put in for the password so that it pulls the user password from
Access. I tried just leaving it as "TemplatePassword", but got the following
error:

Error 4198 Command Failed

Any other ideas?

Connie
 
C

Clifford Bass

Hi Connie,

What data is it that has a password? Is it Access, Word, something
else that is asking for the password? Could you be more specific on what is
being done? Maybe what is in the template?

Clifford Bass
 
C

css

Clifford:

Basically, I'm running a query to search my database for data & put in all
in a temporary table; TempMerge. The word template references this table.
When I log directly in to word to edit the template, I'm asked for my log in
& password for access. I've set up each user in access under Security.

Problem is, when a user has already ready logged in to Access & run the vb
code/query, they are prompted again for their Access user id & password. The
code opens the template (whatever one for each specific item), merges it with
the temp table, prints it & closes Access. The user doesn't even see it
happen on the screen.

I really don't want to make them log in again since it's all happening in
background. I can pull the user id from the CurrentUser, but don't know how
to get the password.

Here's the code:

'look up template name for item
str = "[dept]=" & dept & " AND [cat]=" & cat & " AND [item]=" & item
TName = Nz(DLookup("[Link]", "OffRentLinks", str))
If TName = "" Then
str = MsgBox("No Service Document", vbInformation)
Quit
End If
TName = "S:\Shared Documents\ServiceProcedures\" & TName 'word merge doc to
open
'opens word
Set wordApp = New Word.Application
wordApp.Visible = False 'whether or not to show word, just print
'opens template
Set wordDoc = wordApp.Documents.Open(TName, , , , , "TemplatePassword")
'prints document
wordApp.Options.PrintBackground = False
wordApp.ActiveDocument.PrintOut
'closes document
wordDoc.Close (False)
'closes word
wordApp.Quit

Any ideas?

Connie
 
C

Clifford Bass

Hi Connie,

Unfortunately I am not able to help directly as I do not use the user
level security stuff. Where it is important I usually use a secure backend
that does its own prompting. The users just have to deal with the prompting
when doing the few Word merges that they use.

I do have a few ideas, that may or may not help. Some are predicated
on the output data in the temporary table not needing protection from being
view by anyone with access to the Word template. Probably not a big issue.
Is it possible to tell Word to store the user name and password? If so, you
could set up a generic Merge user that has access to the temporary table. Or
if that does not work, how about a level of indirection--that is create a
separate non-secured database with a linked table to the original database,
again using a generic Merge user and saving the password with the link? Then
use the non-secured database as the source for the Word document. Finally as
another variation, place your temporary table in a non-secured database and
in the main database delete the current temporary table and link to the
temporary table in the non-secure database. Again, use the non-secure
database as the source of the merge data. You could add in removal of the
records from the temporary table at the end of the process.

Hope that is of some help,

Clifford Bass

css said:
Clifford:

Basically, I'm running a query to search my database for data & put in all
in a temporary table; TempMerge. The word template references this table.
When I log directly in to word to edit the template, I'm asked for my log in
& password for access. I've set up each user in access under Security.

Problem is, when a user has already ready logged in to Access & run the vb
code/query, they are prompted again for their Access user id & password. The
code opens the template (whatever one for each specific item), merges it with
the temp table, prints it & closes Access. The user doesn't even see it
happen on the screen.

I really don't want to make them log in again since it's all happening in
background. I can pull the user id from the CurrentUser, but don't know how
to get the password.

Here's the code:

'look up template name for item
str = "[dept]=" & dept & " AND [cat]=" & cat & " AND [item]=" & item
TName = Nz(DLookup("[Link]", "OffRentLinks", str))
If TName = "" Then
str = MsgBox("No Service Document", vbInformation)
Quit
End If
TName = "S:\Shared Documents\ServiceProcedures\" & TName 'word merge doc to
open
'opens word
Set wordApp = New Word.Application
wordApp.Visible = False 'whether or not to show word, just print
'opens template
Set wordDoc = wordApp.Documents.Open(TName, , , , , "TemplatePassword")
'prints document
wordApp.Options.PrintBackground = False
wordApp.ActiveDocument.PrintOut
'closes document
wordDoc.Close (False)
'closes word
wordApp.Quit

Any ideas?

Connie
 
C

css

Clifford:

Thanks for the ideas!

I ended up using TransferText to export the data to a Temp.txt file, then
changed my template to merge on that file instead of the database.

No more password problems!

Thanks again,
Connie


Clifford Bass said:
Hi Connie,

Unfortunately I am not able to help directly as I do not use the user
level security stuff. Where it is important I usually use a secure backend
that does its own prompting. The users just have to deal with the prompting
when doing the few Word merges that they use.

I do have a few ideas, that may or may not help. Some are predicated
on the output data in the temporary table not needing protection from being
view by anyone with access to the Word template. Probably not a big issue.
Is it possible to tell Word to store the user name and password? If so, you
could set up a generic Merge user that has access to the temporary table. Or
if that does not work, how about a level of indirection--that is create a
separate non-secured database with a linked table to the original database,
again using a generic Merge user and saving the password with the link? Then
use the non-secured database as the source for the Word document. Finally as
another variation, place your temporary table in a non-secured database and
in the main database delete the current temporary table and link to the
temporary table in the non-secure database. Again, use the non-secure
database as the source of the merge data. You could add in removal of the
records from the temporary table at the end of the process.

Hope that is of some help,

Clifford Bass

css said:
Clifford:

Basically, I'm running a query to search my database for data & put in all
in a temporary table; TempMerge. The word template references this table.
When I log directly in to word to edit the template, I'm asked for my log in
& password for access. I've set up each user in access under Security.

Problem is, when a user has already ready logged in to Access & run the vb
code/query, they are prompted again for their Access user id & password. The
code opens the template (whatever one for each specific item), merges it with
the temp table, prints it & closes Access. The user doesn't even see it
happen on the screen.

I really don't want to make them log in again since it's all happening in
background. I can pull the user id from the CurrentUser, but don't know how
to get the password.

Here's the code:

'look up template name for item
str = "[dept]=" & dept & " AND [cat]=" & cat & " AND [item]=" & item
TName = Nz(DLookup("[Link]", "OffRentLinks", str))
If TName = "" Then
str = MsgBox("No Service Document", vbInformation)
Quit
End If
TName = "S:\Shared Documents\ServiceProcedures\" & TName 'word merge doc to
open
'opens word
Set wordApp = New Word.Application
wordApp.Visible = False 'whether or not to show word, just print
'opens template
Set wordDoc = wordApp.Documents.Open(TName, , , , , "TemplatePassword")
'prints document
wordApp.Options.PrintBackground = False
wordApp.ActiveDocument.PrintOut
'closes document
wordDoc.Close (False)
'closes word
wordApp.Quit

Any ideas?

Connie
 
C

Clifford Bass

Hi Connie,

You are welcome! That is a good work-around. Thanks for letting me
know how/what you did and that it is working.

Clifford Bass
 

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