| Code: |
Private Sub Offerte_Click()
Dim WordApp As Word.Application
Dim strTemplateLocation As String
Dim strMobiel As String
Dim strMail As String
Dim strVragen As String
Dim strDocname As String
' **** Specify location of template ****
strTemplateLocation = "D:\Offerte\Offerte.Dot"
strDocname = "D:\Offertes\" + Format$(Me.ProjectNrOff, "##-####-####") + "\" + Format$(Me.ProjectNrOff, "##-####-####")
strMobiel = DLookup("[Mobiel]", "QOfferte")
strMail = DLookup("[Mail]", "QOfferte")
strVragen = "Voor vragen over deze aanbieding kunt u contact opnemen met " + Trim(Me.Behandeld) + " op telefoonnummer: " + strMobiel + " of via e-mail: " + strMail + "."
On Error Resume Next
Set WordApp = GetObject(, "Word.Application")
If Err.Number <> 0 Then
Set WordApp = CreateObject("Word.Application")
End If
On Error GoTo ErrHandler
WordApp.Visible = True
WordApp.WindowState = wdWindowStateMaximize
WordApp.Documents.Add Template:=strTemplateLocation, NewTemplate:=False
' **** Replace each bookmark with field contents. ****
With WordApp.Selection
ActiveDocument.Bookmarks("Adres").Range.Text = Me.Adres
ActiveDocument.Bookmarks("OfferteDatum").Range.Text = Nz(Me.OfferteDatum, "")
ActiveDocument.Bookmarks("KlantRef").Range.Text = Nz(Me.KlantRef, "")
ActiveDocument.Bookmarks("JOBRef").Range.Text = Nz(Me.MIJNRef, "")
ActiveDocument.Bookmarks("Naam1").Range.Text = Nz(Me.Behandeld, "")
ActiveDocument.Bookmarks("Mobiel2").Range.Text = Nz(strMobiel, "")
ActiveDocument.Bookmarks("Aanhef").Range.Text = Nz(Me.aanhef, "")
ActiveDocument.Bookmarks("Vragen").Range.Text = strVragen
ActiveDocument.Bookmarks("Naam2").Range.Text = Nz(Me.Behandeld, "")
ActiveDocument.SaveAs (strDocname)
ActiveDocument.Close
End With
WordApp.Quit
Set WordApp = Nothing
Exit Sub
ErrHandler:
Set WordApp = Nothing
End sub
[/color] |