Hello I need this help, I can't run using the query(qryCliente) to export only the list of customers. Only the nameCliente field. In the .docx file I have the Bookmark of the customer nameCliente field.
Error: Undefined variable
Public Sub ExportToWord()
Dim wApp As Word.Application
Dim wDoc As Word.Document
Dim rs As DAO.Recordset
Set wApp = New Word.Application
Set wDoc = wApp.Documents.Open(CurrentProject.Path & "\DBClientes\listCliente.docx")
Set rs = CurrentDb.OpenRecordset(CST_CLIENTE, "nameCliente")
If Not rs.EOF Then rs.MoveFirst
Do Until rs.EOF
wDoc.Bookmarks("nameCliente").Range.Text = Nz(rs!nameCliente, "")
wDoc.SaveAs2 CurrentProject.Path & "" & rs!ID & "_listCliente2.docx"
Set wDoc = wApp.Documents.Open(CurrentProject.Path & "\listCliente2.docx")
If Not wDoc Is Nothing Then
MsgBox "open file!"
Else
MsgBox "file not open!"
End If
wDoc.Bookmarks("nameCliente").Range.Delete wdCharacter, Len(Nz(rs!nameCliente, ""))
rs.MoveNext
Loop
wDoc.Close False
wApp.Quit
Set wDoc = Nothing
Set wApp = Nothing
Set rs = Nothing
End Sub
Error: Undefined variable
Public Sub ExportToWord()
Dim wApp As Word.Application
Dim wDoc As Word.Document
Dim rs As DAO.Recordset
Set wApp = New Word.Application
Set wDoc = wApp.Documents.Open(CurrentProject.Path & "\DBClientes\listCliente.docx")
Set rs = CurrentDb.OpenRecordset(CST_CLIENTE, "nameCliente")
If Not rs.EOF Then rs.MoveFirst
Do Until rs.EOF
wDoc.Bookmarks("nameCliente").Range.Text = Nz(rs!nameCliente, "")
wDoc.SaveAs2 CurrentProject.Path & "" & rs!ID & "_listCliente2.docx"
Set wDoc = wApp.Documents.Open(CurrentProject.Path & "\listCliente2.docx")
If Not wDoc Is Nothing Then
MsgBox "open file!"
Else
MsgBox "file not open!"
End If
wDoc.Bookmarks("nameCliente").Range.Delete wdCharacter, Len(Nz(rs!nameCliente, ""))
rs.MoveNext
Loop
wDoc.Close False
wApp.Quit
Set wDoc = Nothing
Set wApp = Nothing
Set rs = Nothing
End Sub