1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
| Private Sub Command15_Click()
Dim wApp As Word.Application
Dim rs As DAO.Recordset
Dim db As DAO.Database
Dim sql As String
sql = "SELECT * From tblComStart WHERE PatientCode = [PRQ//PRI//Pri//17/12/2012//DNR] ;"
Set db = CurrentDb
Set rs = db.OpenRecordset(sql)
Set wApp = New Word.Application
wApp.Visible = True
While Not rs.EOF
With wApp
.Documents.Open "C:\Users\dnr\Desktop\Bookmarks.docx"
.ActiveDocument.Bookmarks("Name").Range.Text = rs.Fields("PatientName")
.ActiveDocument.Bookmarks("Surname").Range.Text = rs.Fields("PatientSurname")
'.ActiveDocument.PrintOut
'.ActiveDocument.Close (wdDoNotSaveChanges)
End With
rs.MoveNext
Wend
rs.Close
Set rs = Nothing
db.Close
Set db = Nothing
Set wApp = Nothing
End Sub |