Results 1 to 3 of 3
  1. #1
    adaoluz is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2017
    Posts
    46

    Default Export Data To Word, Access 2010

    Hello friends!



    Ok, I have an error on a form where I want to export the data to Word, a "Run-time error '5174', this file could not be found, well I have no file template help me in this situation, thank you.

    Line highlighted with error.






    Code:
    Option Compare DatabaseOption Explicit
    
    
    '******************************************************************************
    '*  Procédure pour l'export de texte vers un document Word
    '*  Utilisé dans le cadre d'un tuto pour le publipostage
    '*
    '******************************************************************************
    
    
    Public Sub TrfText(idctrt As Integer)
    Dim rs01 As Recordset
    Dim rs02 As Recordset 'recordset de la table client
    Dim rs03 As Recordset 'recordset de la table clause
    Dim db As Database
    Dim stSQL01 As String
    Dim stSQL02 As String
    Dim stSQL03 As String
    Dim wApp As Word.Application
    Dim strChemin As String
    
    
    strChemin = CurrentProject.Path
    Set wApp = New Word.Application
    wApp.Visible = True 'permet d'afficher à l'écran le transfert de texte
    'ouverture du document Word
    wApp.Documents.Add Template:=strChemin & "\contrat.dot", NewTemplate:=False, DocumentType:=0
    
    
    stSQL01 = "Select * from tblcontrat where idcontrat =" & idctrt
    
    
    Set db = CurrentDb
    Set rs01 = db.OpenRecordset(stSQL01) 'défnition du premier recordset table contrat
        'insérer le code d'appel pour insertion dans Word
        With wApp.Selection
            .TypeParagraph 'ajoute une ligne en Word
            .TypeText "Contrat  " 'insertion de donnée de type texte
            .TypeText rs01.Fields("idContrat") 'insertion des données issues du recordset
            .TypeParagraph
            .TypeText "En date du  " & rs01.Fields("dtDate")
            .TypeParagraph
            .TypeParagraph
        End With
            
    stSQL02 = "select * from tblclient where idclient =" & rs01.Fields("idclient").Value
    Set rs02 = db.OpenRecordset(stSQL02) 'définition du second recordset table client
        With wApp.Selection
            .TypeParagraph
            .TypeParagraph
            .TypeText rs02.Fields("sttitre") & " " & rs02.Fields("stNom")
            .TypeParagraph
            .TypeText rs02.Fields("stAdresse")
            .TypeParagraph
            .TypeText rs02.Fields("stCP") & "  " & rs02.Fields("stville")
            .TypeParagraph
            .TypeParagraph
        End With
        
    
    
    stSQL03 = "SELECT tblContrat.idContrat, tblClause.idClause, tblClause.stRubrique, tblClause.stClause FROM tblContrat INNER JOIN (tblClause INNER JOIN tblDetailContrat ON tblClause.idClause = tblDetailContrat.idClause) ON tblContrat.idContrat = tblDetailContrat.idContrat WHERE tblContrat.idContrat= " & rs01.Fields("idcontrat")
    Set rs03 = db.OpenRecordset(stSQL03) 'définition de roisième recordset table clause
    While Not rs03.EOF 'boucle pour récuperer les enreistrments de la table liée
        With wApp.Selection
            .TypeText rs03.Fields("strubrique")
            .TypeParagraph
            .TypeText rs03.Fields("stclause")
            .TypeParagraph
            .TypeParagraph
        End With
       rs03.MoveNext
    Wend
    ' libération des objets
    'afin de pourvoir manipuler le fichier Word, l'application n'est pas fermée
    Set rs01 = Nothing
    Set rs02 = Nothing
    Set rs03 = Nothing
    Set db = Nothing
    End Sub

  2. #2
    ranman256's Avatar
    ranman256 is offline VIP
    Windows Vista Access 2010 32bit
    Join Date
    Apr 2014
    Location
    Kentucky
    Posts
    9,521
    the code works IF :
    1.you MUST have the Word X.xx object library in VBE menu: tools, references
    2.strChemin & "\contrat.dot" DOES exist
    3. the last param is true to make it visible.

    Code:
    dim wApp As Word.Application
    Set wApp= CreateObject("word.application")
    
    With wApp
         .Documents.Add strChemin & "\contrat.dot" ,false , 0, TRUE
        
    end with

  3. #3
    adaoluz is offline Advanced Beginner
    Windows 7 32bit Access 2010 32bit
    Join Date
    Oct 2017
    Posts
    46
    Hello .. Good evening!


    I did the tests but unfortunately it did not work.

    the error continues.

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

Similar Threads

  1. How to export access data to word
    By Wolphe in forum Programming
    Replies: 19
    Last Post: 02-02-2018, 10:58 AM
  2. Export Data from Access to Word
    By Byrkster in forum Access
    Replies: 4
    Last Post: 07-22-2016, 08:00 AM
  3. Replies: 0
    Last Post: 01-11-2016, 02:13 AM
  4. Replies: 6
    Last Post: 08-13-2014, 10:32 PM
  5. Replies: 1
    Last Post: 07-22-2013, 01:30 PM

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