dkkirk2000
Registered User.
- Local time
- Today, 02:58
- Joined
- Jan 27, 2017
- Messages
- 16
Hello,
I need some help with this code. I am trying to export several word documents from a query. I can get the 3 documents out but the information keeps adding to the previous doc.
The letters in orange are commented out because if I use them the code doesn't work at all, but I believe is suppose to remove the one country and replace it with the next and so on... (but that doesn't work).
thanks for the help!!!
Here is the code I have:
Public Sub ExportAnnextoWord()
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("C:\Users\kirkwdk\Documents\ECPExample.docx")
Set rs = CurrentDb.OpenRecordset("Annexes Query")
If Not rs.EOF Then rs.MoveFirst
Do Until rs.EOF
wDoc.Bookmarks("Country").Range.Text = Nz(rs!Country, "")
wDoc.Bookmarks("CRNumber").Range.Text = Nz(rs!CRNumber, "")
wDoc.Bookmarks("ECPNumber").Range.Text = Nz(rs!ECPNumber, "")
wDoc.Bookmarks("CRTitle").Range.Text = Nz(rs![CR Title], "")
wDoc.SaveAs2 "C:\Users\kirkwdk\Documents" & rs!ID & "_ECPExample.docx"
' wDoc.Bookmarks("Country").Range.Delete wdCharacter, Len(Nz(rs!Country, ""))
' wDoc.Bookmarks("CRNumber").Range.Delete wdCharacter, Len(Nz(rs!CRNumber, ""))
' wDoc.Bookmarks("ECPNumber").Range.Delete wdCharacter, Len(Nz(rs!ECPNumber, ""))
' wDoc.Bookmarks("CRTitle").Range.Delete wdCharacter, Len(Nz(rs![CR Title], ""))
rs.MoveNext
Loop
wDoc.Close False
wApp.Quit
Set wDoc = Nothing
Set wApp = Nothing
Set rs = Nothing
End Sub
Results:
I need some help with this code. I am trying to export several word documents from a query. I can get the 3 documents out but the information keeps adding to the previous doc.
The letters in orange are commented out because if I use them the code doesn't work at all, but I believe is suppose to remove the one country and replace it with the next and so on... (but that doesn't work).
thanks for the help!!!
Here is the code I have:
Public Sub ExportAnnextoWord()
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("C:\Users\kirkwdk\Documents\ECPExample.docx")
Set rs = CurrentDb.OpenRecordset("Annexes Query")
If Not rs.EOF Then rs.MoveFirst
Do Until rs.EOF
wDoc.Bookmarks("Country").Range.Text = Nz(rs!Country, "")
wDoc.Bookmarks("CRNumber").Range.Text = Nz(rs!CRNumber, "")
wDoc.Bookmarks("ECPNumber").Range.Text = Nz(rs!ECPNumber, "")
wDoc.Bookmarks("CRTitle").Range.Text = Nz(rs![CR Title], "")
wDoc.SaveAs2 "C:\Users\kirkwdk\Documents" & rs!ID & "_ECPExample.docx"
' wDoc.Bookmarks("Country").Range.Delete wdCharacter, Len(Nz(rs!Country, ""))
' wDoc.Bookmarks("CRNumber").Range.Delete wdCharacter, Len(Nz(rs!CRNumber, ""))
' wDoc.Bookmarks("ECPNumber").Range.Delete wdCharacter, Len(Nz(rs!ECPNumber, ""))
' wDoc.Bookmarks("CRTitle").Range.Delete wdCharacter, Len(Nz(rs![CR Title], ""))
rs.MoveNext
Loop
wDoc.Close False
wApp.Quit
Set wDoc = Nothing
Set wApp = Nothing
Set rs = Nothing
End Sub
Results:
KoreaJapanColombia ECP 123451234512345 for CR-033349,-CR-033349,-CR-033349,-
“INITIAL RELEASEINITIAL RELEASELINITIAL RELEASE”