Michael E Phillps said:
Gentlemen I really do appreciate your help but I am completely
confused?? How about if I tell you what I'm trying to do
______________
I have a large legal document for the Social Services Department. I
have created basic intake form in Access with a command button which
is suppose to open a template in Word and enter the data into the
bookmarks.
The template name is Doc1.dot and in sets in this folder
C:\SocServDocs. So I'm going from Access to Word.
Thanks Ever So Much for your help
Mike
That's very much like the routine from which I snipped the code I
posted. Here's the whole routine (with just a few nonessentials
trimmed) in the hope that it may help you:
'----- start of code -----
Function BuildQuoteAsWordDoc( _
Optional PrintIt As Boolean = False, _
Optional SaveIt As Boolean = True) _
As String
' Builds a quote for an item as a Word document.
' Returns the name of the document file created, or a zero-length
' string if no document could be created. If the optional argument
' PrintIt is specified as True, the generated quote document will
' be printed. If the optional argument SaveIt is specified as
False,
' the document will not be saved.
On Error GoTo Err_BuildQuoteAsWordDoc
Dim frmCatalog As Form
Dim appWord As Word.Application
Dim strFileName As String
DoCmd.Hourglass True
' Get a reference to the Catalog form, which *must* be open and
' not at a new record.
Set frmCatalog = Forms("frmCatalogItems")
SysCmd acSysCmdSetStatus, _
"Preparing quote for item " & frmCatalog.StockNo & " ..."
' Get a recordset listing all the available pictures for the current
' item.
Set rsPix = _
CurrentDb.OpenRecordset( _
"SELECT PhotoFile FROM ItemPhotos WHERE StockNo=" & _
frmCatalog.StockNo & _
" ORDER BY IsNull(PhotoOrder) DESC, PhotoOrder ASC")
' Open Word and create a new document based on the template
' we've defined for this purpose.
Set appWord = New Word.Application
appWord.Documents.Add CurrentProject.Path & "\TearSheet.dot"
' The template contains bookmarks for the information
' the quote should contain. Fill them in from the controls
' on this form and on the catalog form.
With appWord.ActiveDocument.Bookmarks
.Item("Customer").Range.Text = Me.txtCustomer & vbNullString
.Item("Address").Range.Text = Me.txtAddress & vbNullString
.Item("QuoteDate").Range.Text = Format(Date, "Long Date")
.Item("StockNo").Range.Text = frmCatalog.StockNo
.Item("Title").Range.Text = frmCatalog.Title & vbNullString
.Item("Description").Range.Text = frmCatalog.Description &
vbNullString
.Item("Dimensions").Range.Text = frmCatalog.Dimensions &
vbNullString
.Item("Price").Range.Text = Format(Me.txtQuotePrice, "$#,##0")
If Not IsNull(frmCatalog.SalesUnit) Then
.Item("SalesUnit").Range.Text = "/" & frmCatalog.SalesUnit
End If
End With
strFileName = CurrentProject.Path & "\QuoteItem" &
frmCatalog.StockNo & ".doc"
With appWord.ActiveDocument
If SaveIt Then
.SaveAs strFileName
End If
If PrintIt Then
.PrintOut Background:=True
End If
End With
BuildQuoteAsWordDoc = strFileName
Exit_BuildQuoteAsWordDoc:
On Error Resume Next
DoCmd.Hourglass False
SysCmd acSysCmdClearStatus
Set frmCatalog = Nothing
' appWord.Visible = True
appWord.Quit False
Set appWord = Nothing
Exit Function
Err_BuildQuoteAsWordDoc:
DoCmd.Hourglass False
MsgBox "Error building quote: " & Err.Description, _
vbExclamation, "Error " & Err.Number
Resume Exit_BuildQuoteAsWordDoc
End Function
'----- end of code -----