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,
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,
Code:
[COLOR=#465584][FONT=Courier]Private Sub ExportToWord_Click()[/FONT][/COLOR]
[COLOR=#465584][FONT=Courier] Dim wApp As Word.Application[/FONT][/COLOR]
[COLOR=#465584][FONT=Courier] Dim wDoc As Word.Document[/FONT][/COLOR]
[COLOR=#465584][FONT=Courier] Dim rs As DAO.Recordset[/FONT][/COLOR]
[COLOR=#465584][FONT=Courier] Set wApp = New Word.Application[/FONT][/COLOR]
[COLOR=#465584][FONT=Courier] Set wDoc = wApp.Documents.Open(CurrentProject.Path & "\ExportLetter.docx")[/FONT][/COLOR]
[COLOR=#465584][FONT=Courier] Set rs = CurrentDb.OpenRecordset("AddressLabelCurrent", dbOpenDynaset)[/FONT][/COLOR]
[COLOR=#465584][FONT=Courier] If Not rs.EOF Then rs.MoveFirst[/FONT][/COLOR]
[COLOR=#465584][FONT=Courier] Do Until rs.EOF[/FONT][/COLOR]
[COLOR=#465584][FONT=Courier] wDoc.Bookmarks("FirstName").Range.Text = Nz(rs!Name, "")[/FONT][/COLOR]
[COLOR=#465584][FONT=Courier] [/FONT][/COLOR]
[COLOR=#465584][FONT=Courier] wDoc.SaveAs2 "CurrentccProject.Path" & rs!StreetAddress & "_documentname.docx"[/FONT][/COLOR]
[COLOR=#465584][FONT=Courier] [/FONT][/COLOR]
[COLOR=#465584][FONT=Courier] wDoc.Bookmarks("FirstName").Range.Delete wdCharacter, Len(Nz(rs!Name, ""))[/FONT][/COLOR]
[COLOR=#465584][FONT=Courier] [/FONT][/COLOR]
[COLOR=#465584][FONT=Courier] rs.MoveNext[/FONT][/COLOR]
[COLOR=#465584][FONT=Courier] Loop[/FONT][/COLOR]
[COLOR=#465584][FONT=Courier] wDoc.Close False[/FONT][/COLOR]
[COLOR=#465584][FONT=Courier] [/FONT][/COLOR]
[COLOR=#465584][FONT=Courier] wApp.Quit[/FONT][/COLOR]
[COLOR=#465584][FONT=Courier] Set wDoc = Nothing[/FONT][/COLOR]
[COLOR=#465584][FONT=Courier] Set wApp = Nothing[/FONT][/COLOR]
[COLOR=#465584][FONT=Courier] Set rs = Nothing[/FONT][/COLOR]