Results 1 to 2 of 2
  1. #1
    Forbes's Avatar
    Forbes is offline Competent Performer
    Windows 10 Access 2016
    Join Date
    Mar 2017
    Posts
    133

    Auto Fill multiple word docs at the same time


    So after figuring out the proper way to fill ou word docs using form fields, I am trying to find the best way to make the script formfill 2 word docs at the same time, I'm using "Case" to select which word docs it fills out based on a combo box selection, currently I have it set to fill out one doc
    Code:
    Private Sub cmdPrint_Click()
    
    
    
    Dim appWord As Word.Application
    Dim CloseWord As String
    Dim doc As Word.Document
    Dim selinv As String
    
    
    'Avoid error 429, when Word isn't open.
    
    
    On Error Resume Next
    
    
    Err.Clear
    
    
    'Set appWord object variable to running instance of Word.
    
    
    Set appWord = GetObject(, "Word.Application")
    
    
    If Err.Number <> 0 Then
    
    
    'If Word isn't open, create a new instance of Word.
    
    
    Set appWord = New Word.Application
    selinv = Me!cmbInv
    
    
    End If
    Select Case strinvsel
    Case "Conv"
    Set doc = appWord.Documents.Open("C:\Sys\Com\Letters\Letters\Letter1.doc", , True)
    With doc
    .FormFields("txtName").Result = Me!TXTAN
    .FormFields("txtAddOne").Result = Me!txtAA1
    .FormFields("txtAddTwo").Result = Me!txtAA2
    .FormFields("txtBor").Result = Me!txtBN
    .FormFields("txtPo").Result = Me!txtPN
    .FormFields("txtInv").Result = Me!txtIN
    .FormFields("txtn1").Result = Me!txtBA1
    .FormFields("txtn2").Result = Me!txtBA2
    .Visible = True
    .Activate
    End With
    ActiveDocument.SaveAs FileName:="L:\Sys\Com\Letters\Letters" & strNewFolderName & "\" & Me!txtBN & "," & "LetterNew1.doc", _
        FileFormat:=wdFormatDocument
    doc.Quit
    If both word docs have the same name in the formfields is there a way to run Letter1 and Letter2 and save them as LetterNew1 and LetterNew2 without rehashing this whole snippet.(there will be 5 "case" options when it's done and 2 letters per "case") So I am trying to simplify it a bit.

  2. #2
    John_G is offline VIP
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2011
    Location
    Ottawa, ON (area)
    Posts
    2,615
    I don't think so. You still have to open each word document in order to fill in the fields. You might be able to put the With...SaveAs block into a sub, and pass doc as parameter (saves having to recreate the Word application each time), provided the Word formfields are consistent.

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Auto Fill with Date and Time
    By Access_Novice123 in forum Access
    Replies: 6
    Last Post: 02-19-2015, 12:04 PM
  2. Replies: 1
    Last Post: 01-10-2012, 09:47 PM
  3. merging check box information into Word Docs
    By LeesKeys in forum Access
    Replies: 1
    Last Post: 10-19-2011, 03:37 PM
  4. Creating Links to Word Docs
    By kingharvest in forum Access
    Replies: 1
    Last Post: 05-19-2010, 10:28 PM
  5. word docs.
    By laqsb in forum Access
    Replies: 1
    Last Post: 02-26-2010, 08:50 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums