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