Export query Access to Word bookmark VBA
I'm trying to make a letter from data from access. I have about 40 or so records to print out on a work document. I've set up the document with bookmarks. I'm getting the data from a query.
So far this sorta runs.... I click the cmd button.... nothing happens. When I click on the actual file name, it says it's read only, then if I click thru it open and then the it runs.... creating saving the 40 or so files in the documents folder. Then when I open one of the word files it is formatted correctly.
I would like it to print these out, don't really need to save them. But, for testing purposes I'm just saving them, I can change that function later.
How do I get this to run from the cmd click? What am I missing?
Thanks,
d
Code:
Private Sub ExportToWord_Click()
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 & "\ExportLetter.docx")
Set rs = CurrentDb.OpenRecordset("AddressLabelCurrent", dbOpenDynaset)
If Not rs.EOF Then rs.MoveFirst
Do Until rs.EOF
wDoc.Bookmarks("FirstName").Range.Text = Nz(rs!Name, "")
wDoc.SaveAs2 "CurrentccProject.Path" & rs!StreetAddress & "_documentname.docx"
wDoc.Bookmarks("FirstName").Range.Delete wdCharacter, Len(Nz(rs!Name, ""))
rs.MoveNext
Loop
wDoc.Close False
wApp.Quit
Set wDoc = Nothing
Set wApp = Nothing
Set rs = Nothing