PDA

View Full Version : Solved: Use Access to Open Series of Word Docs, and return



tca_VB
09-08-2008, 07:11 PM
I've read some similar threads, but not exact so I'm hoping someone can give me a few pointers or head me in the right direction.

I have 50+ word templates (fill-in blank) - complex and need to maintain their look.

I need to create several paths that utilize various combinations of the templates for the user to complete a series of documents and save the word document to a folder. I have created a table that maintains the 6 paths and document order for each, template storage path and name, and save storage path and name.

I would like to have the user click on a button to choose a path, then loop through the documents - open word template, fill in blanks, save/close word document, return to access and loop to next document... I'm having trouble figuring out how to allow the user to fill in items on the word document close/save and return to where they left the access loop.

(Also, this is a low tech environment. I added the DAO library but would prefer to use as few as possible.)

Here's what I have so far (not complete): Any help is appreciated!

Private Sub cmdNewTNClient_Click()
On Error GoTo Err_cmdNewTNClient_Click
Dim oApp As Object
Dim dotString As String
Dim pathString As String
Dim saveString As String
Dim docString As String
Dim intString As Integer
Dim dtDate As Date
Dim numValue As Integer
Dim iCnt As Integer
Dim db As DAO.Database
Dim rs1 As DAO.Recordset
Dim rs2 As DAO.Recordset
Dim nameString As String

Set db = CurrentDb()
Set rs1 = db.OpenRecordset("qryNewTNClient")

rs1.MoveFirst
Do Until rs1.EOF
dotString = rs1![Template_Name]
pathString = rs1![Storage_Location] & "\"

Const conTEMPLATE_NAME = pathString & dotString
'Open Word Instance
Set oApp = CreateObject("Word.Application")
oApp.Visible = True

'Open Template as Document
oApp.Documents.Add Template:=(conTEMPLATE_NAME)
' Save the document.
saveString = "D:\Completed\NewTNClient\"
docString = rs1![Document_Name]
nameString = rs2![Client_Name]
oApp.ActiveDocument.SaveAs FileName:=saveString & nameString & "_" & docString, FileFormat:=wdFormatDocument, LockComments:=False, Password:="", AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData:=False, SaveAsAOCELetter:=False
'oApp.ActiveDocument.Close


' Quit Word.
'oApp.Quit
' Clear the variable from memory.
'Set oApp = Nothing

Loop

rs.Close
Set rs = Nothing
Set db = Nothing

Exit_cmdNewTNClient_Click:
Exit Sub
Err_cmdNewTNClient_Click:
MsgBox Err.Description
End Sub

tca_VB
09-26-2008, 11:58 AM
fyi - I switched to using excel and word cross automation. You can see the solution in http://vbaexpress.com/forum/showthread.php?t=22388 with the help of fumei