I'm trying to run a code for extracting info from a few data fields from a select query and put it into bookmarked places in a word fil. Why doesn't this code work? It runs forever.
Please help!
Public Sub Export()
Dim wApp As Word.Application
Dim wDoc As Word.Document
Dim rs As DAO.Recordset
Dim dbs As DAO.Database
Set wApp = New Word.Application
Set wDoc = wApp.Documents.Open("""*word file*""")
Set dbs = CurrentDb()
Set rs = dbs.OpenRecordset("PersonalData")
rs.MoveFirst
wDoc.Bookmarks("Name").Range.Text = Nz(rs!Name, "")
wDoc.Bookmarks("Date").Range.Text = Nz(rs!Date, "")
wDoc.Bookmarks("Nationality").Range.Text = Nz(rs!Nationality, "")
wDoc.Bookmarks("Email").Range.Text = Nz(rs!Email, "")
wDoc.SaveAs2 "Desktop" & rs!Name & "_PD.docx"
rs.Close
wDoc.Close False
wApp.Quit
Set wApp = Nothing
Set wDoc = Nothing
Set rs = Nothing
End Sub
Please help!
Public Sub Export()
Dim wApp As Word.Application
Dim wDoc As Word.Document
Dim rs As DAO.Recordset
Dim dbs As DAO.Database
Set wApp = New Word.Application
Set wDoc = wApp.Documents.Open("""*word file*""")
Set dbs = CurrentDb()
Set rs = dbs.OpenRecordset("PersonalData")
rs.MoveFirst
wDoc.Bookmarks("Name").Range.Text = Nz(rs!Name, "")
wDoc.Bookmarks("Date").Range.Text = Nz(rs!Date, "")
wDoc.Bookmarks("Nationality").Range.Text = Nz(rs!Nationality, "")
wDoc.Bookmarks("Email").Range.Text = Nz(rs!Email, "")
wDoc.SaveAs2 "Desktop" & rs!Name & "_PD.docx"
rs.Close
wDoc.Close False
wApp.Quit
Set wApp = Nothing
Set wDoc = Nothing
Set rs = Nothing
End Sub