Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2003

    Unanswered: Access and Word and Templates

    I have data in MS-Access. I have a template in MS-Word. I would like to get them to talk to one another. From some reading, it seems as though there are many options that may be used. I wonder which is best?

    1. In MS-Word link (through mail merge) the template document to an MS-Access query which populates the template. If this is the best way to do this, I'd still like to be able to 'trigger' the mail-merge from MS-Access. I don't know how to call MS-Word from MS-Access, open the right template document, and at least start the mail merge.

    2. Create a template in MS-Word (which is linked to an MS-Access query as above), and then imbed that whole MS-Word template as an OLE object in an MS-Access report? I've read that this is possible, but don't know how to do it?

    3. Other options?

    Can someone who's done this before give me some guidance as to the best, most fool-proof method - especially for users who are not conversant in either mail-merging or Access queries. The simpler the better. Still wondering.

    Last edited by cranconsult; 08-13-03 at 17:09.

  2. #2
    Join Date
    Dec 2004

    This should do the trick

    On Error GoTo Err_createFile_ClientInformation

    Dim wd_app As Word.Application
    Dim path As String
    Dim theTemplate As String
    Dim fs As Object
    Dim current As Object
    Dim address As String

    path = "C:\Inetpub\private\" & Me.jobName.Value & "\"
    theTemplate = "C:\Inetpub\private\templates\Client"

    Set wd_app = New Word.Application

    If Dir(path, vbDirectory) = "" Then
    Set fs = CreateObject("Scripting.FileSystemObject")
    fs.createfolder (path)
    End If

    If Dir(path & "Client Information.doc") = "" Then
    wd_app.Documents.Add Template:=theTemplate
    wd_app.ActiveDocument.SaveAs path & "Client Information.doc"
    If Not (IsFileOpen(path & "Client Information.doc")) Then
    wd_app.Documents.Open filename:=path & "Client Information.doc", ReadOnly:=False
    MsgBox "An error occurred while trying to open the file. It may be opened by another user. Please try again later."
    Exit Function
    End If
    End If

    wd_app.Visible = True
    Set current = wd_app.ActiveDocument

    If IsNull(Me.contactPerson) Then
    current.FormFields("jobName").result = Nz(Me.jobName, "Job Name is Required")
    current.FormFields("contactPerson2").result = Nz(Me.jobName, "Contact Person is Required")
    current.FormFields("contactPerson").result = Nz(Me.jobName, "Contact Person is Required")
    current.FormFields("contactPerson").result = Nz(Me.contactPerson, "Name of Contact Person is Required")
    current.FormFields("jobName").result = Nz(Me.jobName, "Job Name is Required")
    current.FormFields("contactPerson2").result = Nz(Me.contactPerson, "Name of Contact Person is Required")
    End If

    current.FormFields("phone").result = Nz(Me.phoneNumber, "")
    current.FormFields("fax").result = Nz(Me.faxNumber, "")
    address = Nz(Me.streetAddress, "") & " " & Nz(, "") & ", " & Nz(UCase(Me.state), "") & " " & Nz(Me.zipCode, "")
    If address <> ", " Then
    current.FormFields("address").result = address
    current.FormFields("address").result = ""
    End If


    Select Case action
    Case actionMODIFY
    ' User wants to open file
    AppActivate "Client Information.doc", False
    Case actionCLOSE
    ' User wants to create file
    Case Else
    MsgBox "Option is not valid."
    End Select

    Set fs = Nothing
    Set wd_app = Nothing
    Set current = Nothing

    Exit Function

    MsgBox Err.Description
    Resume Exit_createFile_ClientInformation

    End Function

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts